synapsecns/sanguine

View on GitHub
agents/contracts/lightmanager/lightmanager.contractinfo.json

Summary

Maintainability
Test Coverage
{"solidity/LightManager.sol:AddressUpgradeable":{"code":"0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea264697066735822122067aaddc0dff892c350ed3e97cd6d6fcda516b06100b09117efe3d9d79d5bb17364736f6c63430008110033","runtime-code":"0x73000000000000000000000000000000000000000030146080604052600080fdfea264697066735822122067aaddc0dff892c350ed3e97cd6d6fcda516b06100b09117efe3d9d79d5bb17364736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"76073:9180:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;76073:9180:0;;;;;;;;;;;;;;;;;","srcMapRuntime":"76073:9180:0:-:0;;;;;;;;","abiDefinition":[],"userDoc":{"kind":"user","methods":{},"version":1},"developerDoc":{"details":"Collection of functions related to the address type","kind":"dev","methods":{},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"details\":\"Collection of functions related to the address type\",\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"AddressUpgradeable\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{}},"solidity/LightManager.sol:AgentManager":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"inputs":[],"name":"AgentNotActiveNorUnstaking","type":"error"},{"inputs":[],"name":"CallerNotInbox","type":"error"},{"inputs":[],"name":"DisputeAlreadyResolved","type":"error"},{"inputs":[],"name":"GuardInDispute","type":"error"},{"inputs":[],"name":"IncorrectAgentDomain","type":"error"},{"inputs":[],"name":"IncorrectVersionLength","type":"error"},{"inputs":[],"name":"IndexOutOfRange","type":"error"},{"inputs":[],"name":"NotaryInDispute","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"newRoot","type":"bytes32"}],"name":"AgentRootProposed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"disputeIndex","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"guardIndex","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"notaryIndex","type":"uint32"}],"name":"DisputeOpened","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"disputeIndex","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"slashedIndex","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"rivalIndex","type":"uint32"},{"indexed":false,"internalType":"address","name":"fraudProver","type":"address"}],"name":"DisputeResolved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"proposedRoot","type":"bytes32"}],"name":"ProposedAgentRootCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"proposedRoot","type":"bytes32"}],"name":"ProposedAgentRootResolved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"newRoot","type":"bytes32"}],"name":"RootUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"indexed":true,"internalType":"uint32","name":"domain","type":"uint32"},{"indexed":true,"internalType":"address","name":"agent","type":"address"}],"name":"StatusUpdated","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"agentRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"}],"name":"agentStatus","outputs":[{"components":[{"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"uint32","name":"index","type":"uint32"}],"internalType":"struct AgentStatus","name":"status","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"destination","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"}],"name":"disputeStatus","outputs":[{"internalType":"enum DisputeFlag","name":"flag","type":"uint8"},{"internalType":"address","name":"rival","type":"address"},{"internalType":"address","name":"fraudProver","type":"address"},{"internalType":"uint256","name":"disputePtr","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getAgent","outputs":[{"internalType":"address","name":"agent","type":"address"},{"components":[{"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"uint32","name":"index","type":"uint32"}],"internalType":"struct AgentStatus","name":"status","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getDispute","outputs":[{"internalType":"address","name":"guard","type":"address"},{"internalType":"address","name":"notary","type":"address"},{"internalType":"address","name":"slashedAgent","type":"address"},{"internalType":"address","name":"fraudProver","type":"address"},{"internalType":"bytes","name":"reportPayload","type":"bytes"},{"internalType":"bytes","name":"reportSignature","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDisputesAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"inbox","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"localDomain","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"allowFailure","type":"bool"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct MultiCallable.Call[]","name":"calls","type":"tuple[]"}],"name":"multicall","outputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"}],"internalType":"struct MultiCallable.Result[]","name":"callResults","type":"tuple[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"guardIndex","type":"uint32"},{"internalType":"uint32","name":"notaryIndex","type":"uint32"}],"name":"openDispute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"origin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"address","name":"agent","type":"address"},{"internalType":"address","name":"prover","type":"address"}],"name":"slashAgent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"synapseDomain","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"versionString","type":"string"}],"stateMutability":"view","type":"function"}],"userDoc":{"events":{"AgentRootProposed(bytes32)":{"notice":"Emitted after the contract owner proposes a new agent root to resolve the stuck chain."},"DisputeOpened(uint256,uint32,uint32)":{"notice":"Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits their report for the Notary-signed statement to `StatementInbox`."},"DisputeResolved(uint256,uint32,uint32,address)":{"notice":"Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed. Note: this won't be emitted, if an Agent was slashed without being in Dispute."},"ProposedAgentRootCancelled(bytes32)":{"notice":"Emitted after the contract owner cancels the previously proposed agent root."},"ProposedAgentRootResolved(bytes32)":{"notice":"Emitted after the contract owner resolves the previously proposed agent root."},"RootUpdated(bytes32)":{"notice":"Emitted whenever the root of the Agent Merkle Tree is updated."},"StatusUpdated(uint8,uint32,address)":{"notice":"Emitted whenever a status of the agent is updated."}},"kind":"user","methods":{"agentRoot()":{"notice":"Returns the latest known root of the Agent Merkle Tree."},"agentStatus(address)":{"notice":"Returns (flag, domain, index) for a given agent. See Structures.sol for details."},"disputeStatus(address)":{"notice":"Returns the current Dispute status of a given agent. See Structures.sol for details."},"getAgent(uint256)":{"notice":"Returns agent address and their current status for a given agent index."},"getDispute(uint256)":{"notice":"Returns information about the dispute with the given index."},"getDisputesAmount()":{"notice":"Returns the number of opened Disputes."},"localDomain()":{"notice":"Domain of the local chain, set once upon contract creation"},"multicall((bool,bytes)[])":{"notice":"Aggregates a few calls to this contract into one multicall without modifying `msg.sender`."},"openDispute(uint32,uint32)":{"notice":"Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Guard or Notary is already in Dispute."},"slashAgent(uint32,address,address)":{"notice":"Allows Inbox to slash an agent, if their fraud was proven. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Domain doesn't match the saved agent domain."}},"notice":"`AgentManager` is used to keep track of all the bonded agents and their statuses. The exact logic of how the agent statuses are stored and updated is implemented in child contracts, and depends on whether the contract is used on Synapse Chain or on other chains. `AgentManager` is responsible for the following: - Keeping track of all the bonded agents and their statuses. - Keeping track of all the disputes between agents. - Notifying `AgentSecured` contracts about the opened and resolved disputes. - Notifying `AgentSecured` contracts about the slashed agents.","version":1},"developerDoc":{"kind":"dev","methods":{"acceptOwnership()":{"details":"The new owner accepts the ownership transfer."},"agentStatus(address)":{"details":"Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud, but their status is not updated to Slashed yet.","params":{"agent":"Agent address"},"returns":{"status":"Status for the given agent: (flag, domain, index)."}},"disputeStatus(address)":{"details":"Every returned value will be set to zero if agent was not slashed and is not in Dispute. `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.","params":{"agent":"Agent address"},"returns":{"disputePtr":"  Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.","flag":"        Flag describing the current Dispute status for the agent: None/Pending/Slashed","fraudProver":" Address who provided fraud proof to resolve the Dispute","rival":"       Address of the rival agent in the Dispute"}},"getAgent(uint256)":{"details":"Will return empty values if agent with given index doesn't exist.","params":{"index":"Agent index in the Agent Merkle Tree"},"returns":{"agent":"   Agent address","status":"  Status for the given agent: (flag, domain, index)"}},"getDispute(uint256)":{"details":"Will revert if dispute with given index hasn't been opened yet.","params":{"index":"Dispute index"},"returns":{"fraudProver":"     Address who provided fraud proof to resolve the Dispute","guard":"           Address of the Guard in the Dispute","notary":"          Address of the Notary in the Dispute","reportPayload":"   Raw payload with report data that led to the Dispute","reportSignature":" Guard signature for the report payload","slashedAgent":"    Address of the Agent who was slashed when Dispute was resolved"}},"getDisputesAmount()":{"details":"This includes the Disputes that have been resolved already."},"openDispute(uint32,uint32)":{"params":{"guardIndex":"Index of the Guard in the Agent Merkle Tree","notaryIndex":"Index of the Notary in the Agent Merkle Tree"}},"owner()":{"details":"Returns the address of the current owner."},"pendingOwner()":{"details":"Returns the address of the pending owner."},"renounceOwnership()":{"details":"Should be impossible to renounce ownership; we override OpenZeppelin OwnableUpgradeable's implementation of renounceOwnership to make it a no-op"},"slashAgent(uint32,address,address)":{"params":{"agent":"Address of the Agent","domain":"Domain where the Agent is active","prover":"Address that initially provided fraud proof"}},"transferOwnership(address)":{"details":"Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner."}},"stateVariables":{"__GAP":{"details":"gap for upgrade safety"}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"AgentNotActiveNorUnstaking\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CallerNotInbox\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"DisputeAlreadyResolved\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"GuardInDispute\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"IncorrectAgentDomain\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"IncorrectVersionLength\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"IndexOutOfRange\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotaryInDispute\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"newRoot\",\"type\":\"bytes32\"}],\"name\":\"AgentRootProposed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"disputeIndex\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"guardIndex\",\"type\":\"uint32\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"notaryIndex\",\"type\":\"uint32\"}],\"name\":\"DisputeOpened\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"disputeIndex\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"slashedIndex\",\"type\":\"uint32\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"rivalIndex\",\"type\":\"uint32\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"fraudProver\",\"type\":\"address\"}],\"name\":\"DisputeResolved\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"version\",\"type\":\"uint8\"}],\"name\":\"Initialized\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferStarted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"proposedRoot\",\"type\":\"bytes32\"}],\"name\":\"ProposedAgentRootCancelled\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"proposedRoot\",\"type\":\"bytes32\"}],\"name\":\"ProposedAgentRootResolved\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"newRoot\",\"type\":\"bytes32\"}],\"name\":\"RootUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"indexed\":true,\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"StatusUpdated\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"acceptOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"agentRoot\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"agentStatus\",\"outputs\":[{\"components\":[{\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"index\",\"type\":\"uint32\"}],\"internalType\":\"struct AgentStatus\",\"name\":\"status\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"destination\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"disputeStatus\",\"outputs\":[{\"internalType\":\"enum DisputeFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"address\",\"name\":\"rival\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"fraudProver\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"disputePtr\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getAgent\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"index\",\"type\":\"uint32\"}],\"internalType\":\"struct AgentStatus\",\"name\":\"status\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getDispute\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"guard\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"notary\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"slashedAgent\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"fraudProver\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"reportPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"reportSignature\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getDisputesAmount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"inbox\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"localDomain\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bool\",\"name\":\"allowFailure\",\"type\":\"bool\"},{\"internalType\":\"bytes\",\"name\":\"callData\",\"type\":\"bytes\"}],\"internalType\":\"struct MultiCallable.Call[]\",\"name\":\"calls\",\"type\":\"tuple[]\"}],\"name\":\"multicall\",\"outputs\":[{\"components\":[{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"},{\"internalType\":\"bytes\",\"name\":\"returnData\",\"type\":\"bytes\"}],\"internalType\":\"struct MultiCallable.Result[]\",\"name\":\"callResults\",\"type\":\"tuple[]\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"guardIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"notaryIndex\",\"type\":\"uint32\"}],\"name\":\"openDispute\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"origin\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pendingOwner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"prover\",\"type\":\"address\"}],\"name\":\"slashAgent\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"synapseDomain\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"versionString\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"acceptOwnership()\":{\"details\":\"The new owner accepts the ownership transfer.\"},\"agentStatus(address)\":{\"details\":\"Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud, but their status is not updated to Slashed yet.\",\"params\":{\"agent\":\"Agent address\"},\"returns\":{\"status\":\"Status for the given agent: (flag, domain, index).\"}},\"disputeStatus(address)\":{\"details\":\"Every returned value will be set to zero if agent was not slashed and is not in Dispute. `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\",\"params\":{\"agent\":\"Agent address\"},\"returns\":{\"disputePtr\":\"  Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\",\"flag\":\"        Flag describing the current Dispute status for the agent: None/Pending/Slashed\",\"fraudProver\":\" Address who provided fraud proof to resolve the Dispute\",\"rival\":\"       Address of the rival agent in the Dispute\"}},\"getAgent(uint256)\":{\"details\":\"Will return empty values if agent with given index doesn't exist.\",\"params\":{\"index\":\"Agent index in the Agent Merkle Tree\"},\"returns\":{\"agent\":\"   Agent address\",\"status\":\"  Status for the given agent: (flag, domain, index)\"}},\"getDispute(uint256)\":{\"details\":\"Will revert if dispute with given index hasn't been opened yet.\",\"params\":{\"index\":\"Dispute index\"},\"returns\":{\"fraudProver\":\"     Address who provided fraud proof to resolve the Dispute\",\"guard\":\"           Address of the Guard in the Dispute\",\"notary\":\"          Address of the Notary in the Dispute\",\"reportPayload\":\"   Raw payload with report data that led to the Dispute\",\"reportSignature\":\" Guard signature for the report payload\",\"slashedAgent\":\"    Address of the Agent who was slashed when Dispute was resolved\"}},\"getDisputesAmount()\":{\"details\":\"This includes the Disputes that have been resolved already.\"},\"openDispute(uint32,uint32)\":{\"params\":{\"guardIndex\":\"Index of the Guard in the Agent Merkle Tree\",\"notaryIndex\":\"Index of the Notary in the Agent Merkle Tree\"}},\"owner()\":{\"details\":\"Returns the address of the current owner.\"},\"pendingOwner()\":{\"details\":\"Returns the address of the pending owner.\"},\"renounceOwnership()\":{\"details\":\"Should be impossible to renounce ownership; we override OpenZeppelin OwnableUpgradeable's implementation of renounceOwnership to make it a no-op\"},\"slashAgent(uint32,address,address)\":{\"params\":{\"agent\":\"Address of the Agent\",\"domain\":\"Domain where the Agent is active\",\"prover\":\"Address that initially provided fraud proof\"}},\"transferOwnership(address)\":{\"details\":\"Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.\"}},\"stateVariables\":{\"__GAP\":{\"details\":\"gap for upgrade safety\"}},\"version\":1},\"userdoc\":{\"events\":{\"AgentRootProposed(bytes32)\":{\"notice\":\"Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\"},\"DisputeOpened(uint256,uint32,uint32)\":{\"notice\":\"Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits their report for the Notary-signed statement to `StatementInbox`.\"},\"DisputeResolved(uint256,uint32,uint32,address)\":{\"notice\":\"Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed. Note: this won't be emitted, if an Agent was slashed without being in Dispute.\"},\"ProposedAgentRootCancelled(bytes32)\":{\"notice\":\"Emitted after the contract owner cancels the previously proposed agent root.\"},\"ProposedAgentRootResolved(bytes32)\":{\"notice\":\"Emitted after the contract owner resolves the previously proposed agent root.\"},\"RootUpdated(bytes32)\":{\"notice\":\"Emitted whenever the root of the Agent Merkle Tree is updated.\"},\"StatusUpdated(uint8,uint32,address)\":{\"notice\":\"Emitted whenever a status of the agent is updated.\"}},\"kind\":\"user\",\"methods\":{\"agentRoot()\":{\"notice\":\"Returns the latest known root of the Agent Merkle Tree.\"},\"agentStatus(address)\":{\"notice\":\"Returns (flag, domain, index) for a given agent. See Structures.sol for details.\"},\"disputeStatus(address)\":{\"notice\":\"Returns the current Dispute status of a given agent. See Structures.sol for details.\"},\"getAgent(uint256)\":{\"notice\":\"Returns agent address and their current status for a given agent index.\"},\"getDispute(uint256)\":{\"notice\":\"Returns information about the dispute with the given index.\"},\"getDisputesAmount()\":{\"notice\":\"Returns the number of opened Disputes.\"},\"localDomain()\":{\"notice\":\"Domain of the local chain, set once upon contract creation\"},\"multicall((bool,bytes)[])\":{\"notice\":\"Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\"},\"openDispute(uint32,uint32)\":{\"notice\":\"Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Guard or Notary is already in Dispute.\"},\"slashAgent(uint32,address,address)\":{\"notice\":\"Allows Inbox to slash an agent, if their fraud was proven. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Domain doesn't match the saved agent domain.\"}},\"notice\":\"`AgentManager` is used to keep track of all the bonded agents and their statuses. The exact logic of how the agent statuses are stored and updated is implemented in child contracts, and depends on whether the contract is used on Synapse Chain or on other chains. `AgentManager` is responsible for the following: - Keeping track of all the bonded agents and their statuses. - Keeping track of all the disputes between agents. - Notifying `AgentSecured` contracts about the opened and resolved disputes. - Notifying `AgentSecured` contracts about the slashed agents.\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"AgentManager\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"acceptOwnership()":"79ba5097","agentRoot()":"36cba43c","agentStatus(address)":"28f3fac9","destination()":"b269681d","disputeStatus(address)":"3463d1b1","getAgent(uint256)":"2de5aaf7","getDispute(uint256)":"e3a96cbd","getDisputesAmount()":"3aaeccc6","inbox()":"fb0e722b","localDomain()":"8d3638f4","multicall((bool,bytes)[])":"60fc8466","openDispute(uint32,uint32)":"a2155c34","origin()":"938b5f32","owner()":"8da5cb5b","pendingOwner()":"e30c3978","renounceOwnership()":"715018a6","slashAgent(uint32,address,address)":"2853a0e6","synapseDomain()":"717b8638","transferOwnership(address)":"f2fde38b","version()":"54fd4d50"}},"solidity/LightManager.sol:AgentManagerEvents":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"newRoot","type":"bytes32"}],"name":"AgentRootProposed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"disputeIndex","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"guardIndex","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"notaryIndex","type":"uint32"}],"name":"DisputeOpened","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"disputeIndex","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"slashedIndex","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"rivalIndex","type":"uint32"},{"indexed":false,"internalType":"address","name":"fraudProver","type":"address"}],"name":"DisputeResolved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"proposedRoot","type":"bytes32"}],"name":"ProposedAgentRootCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"proposedRoot","type":"bytes32"}],"name":"ProposedAgentRootResolved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"newRoot","type":"bytes32"}],"name":"RootUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"indexed":true,"internalType":"uint32","name":"domain","type":"uint32"},{"indexed":true,"internalType":"address","name":"agent","type":"address"}],"name":"StatusUpdated","type":"event"}],"userDoc":{"events":{"AgentRootProposed(bytes32)":{"notice":"Emitted after the contract owner proposes a new agent root to resolve the stuck chain."},"DisputeOpened(uint256,uint32,uint32)":{"notice":"Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits their report for the Notary-signed statement to `StatementInbox`."},"DisputeResolved(uint256,uint32,uint32,address)":{"notice":"Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed. Note: this won't be emitted, if an Agent was slashed without being in Dispute."},"ProposedAgentRootCancelled(bytes32)":{"notice":"Emitted after the contract owner cancels the previously proposed agent root."},"ProposedAgentRootResolved(bytes32)":{"notice":"Emitted after the contract owner resolves the previously proposed agent root."},"RootUpdated(bytes32)":{"notice":"Emitted whenever the root of the Agent Merkle Tree is updated."},"StatusUpdated(uint8,uint32,address)":{"notice":"Emitted whenever a status of the agent is updated."}},"kind":"user","methods":{},"version":1},"developerDoc":{"events":{"AgentRootProposed(bytes32)":{"params":{"newRoot":"New agent merkle root that was proposed"}},"DisputeOpened(uint256,uint32,uint32)":{"params":{"disputeIndex":"Index of the dispute in the global list of all opened disputes","guardIndex":"Index of the Guard in the Agent Merkle Tree","notaryIndex":"Index of the Notary in the Agent Merkle Tree"}},"DisputeResolved(uint256,uint32,uint32,address)":{"params":{"disputeIndex":"Index of the dispute in the global list of all opened disputes","fraudProver":"Address who provided fraud proof to resolve the Dispute","rivalIndex":"Index of the rival agent in the Agent Merkle Tree","slashedIndex":"Index of the slashed agent in the Agent Merkle Tree"}},"ProposedAgentRootCancelled(bytes32)":{"params":{"proposedRoot":"Agent merkle root that was proposed"}},"ProposedAgentRootResolved(bytes32)":{"params":{"proposedRoot":"New agent merkle root that was resolved"}},"RootUpdated(bytes32)":{"params":{"newRoot":"New agent merkle root"}},"StatusUpdated(uint8,uint32,address)":{"details":"Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree. Unknown flag is the default (zero) value and is used to represent agents that never interacted with the BondingManager contract. Fraudulent flag is the value for the agent who has been proven to commit fraud, but their status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact that the update of the status requires a merkle proof of the old status, and happens in a separate transaction because of that.","params":{"agent":"Agent address","domain":"Domain assigned to the agent (ZERO for Guards)","flag":"Flag defining agent status:"}}},"kind":"dev","methods":{},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"newRoot\",\"type\":\"bytes32\"}],\"name\":\"AgentRootProposed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"disputeIndex\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"guardIndex\",\"type\":\"uint32\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"notaryIndex\",\"type\":\"uint32\"}],\"name\":\"DisputeOpened\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"disputeIndex\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"slashedIndex\",\"type\":\"uint32\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"rivalIndex\",\"type\":\"uint32\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"fraudProver\",\"type\":\"address\"}],\"name\":\"DisputeResolved\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"proposedRoot\",\"type\":\"bytes32\"}],\"name\":\"ProposedAgentRootCancelled\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"proposedRoot\",\"type\":\"bytes32\"}],\"name\":\"ProposedAgentRootResolved\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"newRoot\",\"type\":\"bytes32\"}],\"name\":\"RootUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"indexed\":true,\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"StatusUpdated\",\"type\":\"event\"}],\"devdoc\":{\"events\":{\"AgentRootProposed(bytes32)\":{\"params\":{\"newRoot\":\"New agent merkle root that was proposed\"}},\"DisputeOpened(uint256,uint32,uint32)\":{\"params\":{\"disputeIndex\":\"Index of the dispute in the global list of all opened disputes\",\"guardIndex\":\"Index of the Guard in the Agent Merkle Tree\",\"notaryIndex\":\"Index of the Notary in the Agent Merkle Tree\"}},\"DisputeResolved(uint256,uint32,uint32,address)\":{\"params\":{\"disputeIndex\":\"Index of the dispute in the global list of all opened disputes\",\"fraudProver\":\"Address who provided fraud proof to resolve the Dispute\",\"rivalIndex\":\"Index of the rival agent in the Agent Merkle Tree\",\"slashedIndex\":\"Index of the slashed agent in the Agent Merkle Tree\"}},\"ProposedAgentRootCancelled(bytes32)\":{\"params\":{\"proposedRoot\":\"Agent merkle root that was proposed\"}},\"ProposedAgentRootResolved(bytes32)\":{\"params\":{\"proposedRoot\":\"New agent merkle root that was resolved\"}},\"RootUpdated(bytes32)\":{\"params\":{\"newRoot\":\"New agent merkle root\"}},\"StatusUpdated(uint8,uint32,address)\":{\"details\":\"Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree. Unknown flag is the default (zero) value and is used to represent agents that never interacted with the BondingManager contract. Fraudulent flag is the value for the agent who has been proven to commit fraud, but their status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact that the update of the status requires a merkle proof of the old status, and happens in a separate transaction because of that.\",\"params\":{\"agent\":\"Agent address\",\"domain\":\"Domain assigned to the agent (ZERO for Guards)\",\"flag\":\"Flag defining agent status:\"}}},\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"events\":{\"AgentRootProposed(bytes32)\":{\"notice\":\"Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\"},\"DisputeOpened(uint256,uint32,uint32)\":{\"notice\":\"Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits their report for the Notary-signed statement to `StatementInbox`.\"},\"DisputeResolved(uint256,uint32,uint32,address)\":{\"notice\":\"Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed. Note: this won't be emitted, if an Agent was slashed without being in Dispute.\"},\"ProposedAgentRootCancelled(bytes32)\":{\"notice\":\"Emitted after the contract owner cancels the previously proposed agent root.\"},\"ProposedAgentRootResolved(bytes32)\":{\"notice\":\"Emitted after the contract owner resolves the previously proposed agent root.\"},\"RootUpdated(bytes32)\":{\"notice\":\"Emitted whenever the root of the Agent Merkle Tree is updated.\"},\"StatusUpdated(uint8,uint32,address)\":{\"notice\":\"Emitted whenever a status of the agent is updated.\"}},\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"AgentManagerEvents\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{}},"solidity/LightManager.sol:ChainContext":{"code":"0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220aa2bc7a4205a82fe3dd6a72bff8e6f9243f14d6b645662df4d1b00a4d2936ef764736f6c63430008110033","runtime-code":"0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220aa2bc7a4205a82fe3dd6a72bff8e6f9243f14d6b645662df4d1b00a4d2936ef764736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"89039:976:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;89039:976:0;;;;;;;;;;;;;;;;;","srcMapRuntime":"89039:976:0:-:0;;;;;;;;","abiDefinition":[],"userDoc":{"kind":"user","methods":{},"notice":"Library for accessing chain context variables as tightly packed integers. Messaging contracts should rely on this library for accessing chain context variables instead of doing the casting themselves.","version":1},"developerDoc":{"kind":"dev","methods":{},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"notice\":\"Library for accessing chain context variables as tightly packed integers. Messaging contracts should rely on this library for accessing chain context variables instead of doing the casting themselves.\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"ChainContext\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{}},"solidity/LightManager.sol:ContextUpgradeable":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"}],"userDoc":{"kind":"user","methods":{},"version":1},"developerDoc":{"details":"Provides information about the current execution context, including the sender of the transaction and its data. While these are generally available via msg.sender and msg.data, they should not be accessed in such a direct manner, since when dealing with meta-transactions the account sending and paying for execution may not be the actual sender (as far as an application is concerned). This contract is only required for intermediate, library-like contracts.","kind":"dev","methods":{},"stateVariables":{"__gap":{"details":"This empty reserved space is put in place to allow future versions to add new variables without shifting down storage in the inheritance chain. See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps"}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"version\",\"type\":\"uint8\"}],\"name\":\"Initialized\",\"type\":\"event\"}],\"devdoc\":{\"details\":\"Provides information about the current execution context, including the sender of the transaction and its data. While these are generally available via msg.sender and msg.data, they should not be accessed in such a direct manner, since when dealing with meta-transactions the account sending and paying for execution may not be the actual sender (as far as an application is concerned). This contract is only required for intermediate, library-like contracts.\",\"kind\":\"dev\",\"methods\":{},\"stateVariables\":{\"__gap\":{\"details\":\"This empty reserved space is put in place to allow future versions to add new variables without shifting down storage in the inheritance chain. See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"ContextUpgradeable\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{}},"solidity/LightManager.sol:GasDataLib":{"code":"0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea264697066735822122051080467cf92d45b355d3f30f959701154ef3e09204aa5dd2d8e2565a9dba1aa64736f6c63430008110033","runtime-code":"0x73000000000000000000000000000000000000000030146080604052600080fdfea264697066735822122051080467cf92d45b355d3f30f959701154ef3e09204aa5dd2d8e2565a9dba1aa64736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"107083:7222:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;107083:7222:0;;;;;;;;;;;;;;;;;","srcMapRuntime":"107083:7222:0:-:0;;;;;;;;","abiDefinition":[],"userDoc":{"kind":"user","methods":{},"notice":"Library for encoding and decoding GasData and ChainGas structs. # GasData `GasData` is a struct to store the \"basic information about gas prices\", that could be later used to approximate the cost of a message execution, and thus derive the minimal tip values for sending a message to the chain. \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the \u003e approximates instead of the exact values, and thus save on storage costs. \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an \u003e 0.4% error on the approximates would be acceptable. `GasData` is supposed to be included in the Origin's state, which are synced across chains using Agent-signed snapshots and attestations. ## GasData stack layout (from highest bits to lowest) | Position   | Field        | Type   | Bytes | Description                                         | | ---------- | ------------ | ------ | ----- | --------------------------------------------------- | | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       | | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         | | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) | | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  | | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) | | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          | \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math. ## ChainGas stack layout (from highest bits to lowest) | Position   | Field   | Type   | Bytes | Description      | | ---------- | ------- | ------ | ----- | ---------------- | | (016..004] | gasData | uint96 | 12    | Chain's gas data | | (004..000] | domain  | uint32 | 4     | Chain's domain   |","version":1},"developerDoc":{"kind":"dev","methods":{},"stateVariables":{"SHIFT_AMORT_ATT_COST":{"details":"Amount of bits to shift to amortAttCost field"},"SHIFT_DATA_PRICE":{"details":"Amount of bits to shift to dataPrice field"},"SHIFT_ETHER_PRICE":{"details":"Amount of bits to shift to etherPrice field"},"SHIFT_EXEC_BUFFER":{"details":"Amount of bits to shift to execBuffer field"},"SHIFT_GAS_DATA":{"details":"Amount of bits to shift to gasData field"},"SHIFT_GAS_PRICE":{"details":"Amount of bits to shift to gasPrice field"}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"stateVariables\":{\"SHIFT_AMORT_ATT_COST\":{\"details\":\"Amount of bits to shift to amortAttCost field\"},\"SHIFT_DATA_PRICE\":{\"details\":\"Amount of bits to shift to dataPrice field\"},\"SHIFT_ETHER_PRICE\":{\"details\":\"Amount of bits to shift to etherPrice field\"},\"SHIFT_EXEC_BUFFER\":{\"details\":\"Amount of bits to shift to execBuffer field\"},\"SHIFT_GAS_DATA\":{\"details\":\"Amount of bits to shift to gasData field\"},\"SHIFT_GAS_PRICE\":{\"details\":\"Amount of bits to shift to gasPrice field\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"notice\":\"Library for encoding and decoding GasData and ChainGas structs. # GasData `GasData` is a struct to store the \\\"basic information about gas prices\\\", that could be later used to approximate the cost of a message execution, and thus derive the minimal tip values for sending a message to the chain. \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the \u003e approximates instead of the exact values, and thus save on storage costs. \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an \u003e 0.4% error on the approximates would be acceptable. `GasData` is supposed to be included in the Origin's state, which are synced across chains using Agent-signed snapshots and attestations. ## GasData stack layout (from highest bits to lowest) | Position   | Field        | Type   | Bytes | Description                                         | | ---------- | ------------ | ------ | ----- | --------------------------------------------------- | | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       | | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         | | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) | | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  | | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) | | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          | \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math. ## ChainGas stack layout (from highest bits to lowest) | Position   | Field   | Type   | Bytes | Description      | | ---------- | ------- | ------ | ----- | ---------------- | | (016..004] | gasData | uint96 | 12    | Chain's gas data | | (004..000] | domain  | uint32 | 4     | Chain's domain   |\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"GasDataLib\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{}},"solidity/LightManager.sol:IAgentManager":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"inputs":[],"name":"agentRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"}],"name":"agentStatus","outputs":[{"components":[{"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"uint32","name":"index","type":"uint32"}],"internalType":"struct AgentStatus","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"}],"name":"disputeStatus","outputs":[{"internalType":"enum DisputeFlag","name":"flag","type":"uint8"},{"internalType":"address","name":"rival","type":"address"},{"internalType":"address","name":"fraudProver","type":"address"},{"internalType":"uint256","name":"disputePtr","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getAgent","outputs":[{"internalType":"address","name":"agent","type":"address"},{"components":[{"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"uint32","name":"index","type":"uint32"}],"internalType":"struct AgentStatus","name":"status","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getDispute","outputs":[{"internalType":"address","name":"guard","type":"address"},{"internalType":"address","name":"notary","type":"address"},{"internalType":"address","name":"slashedAgent","type":"address"},{"internalType":"address","name":"fraudProver","type":"address"},{"internalType":"bytes","name":"reportPayload","type":"bytes"},{"internalType":"bytes","name":"reportSignature","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDisputesAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"guardIndex","type":"uint32"},{"internalType":"uint32","name":"notaryIndex","type":"uint32"}],"name":"openDispute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"address","name":"agent","type":"address"},{"internalType":"address","name":"prover","type":"address"}],"name":"slashAgent","outputs":[],"stateMutability":"nonpayable","type":"function"}],"userDoc":{"kind":"user","methods":{"agentRoot()":{"notice":"Returns the latest known root of the Agent Merkle Tree."},"agentStatus(address)":{"notice":"Returns (flag, domain, index) for a given agent. See Structures.sol for details."},"disputeStatus(address)":{"notice":"Returns the current Dispute status of a given agent. See Structures.sol for details."},"getAgent(uint256)":{"notice":"Returns agent address and their current status for a given agent index."},"getDispute(uint256)":{"notice":"Returns information about the dispute with the given index."},"getDisputesAmount()":{"notice":"Returns the number of opened Disputes."},"openDispute(uint32,uint32)":{"notice":"Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Guard or Notary is already in Dispute."},"slashAgent(uint32,address,address)":{"notice":"Allows Inbox to slash an agent, if their fraud was proven. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Domain doesn't match the saved agent domain."}},"version":1},"developerDoc":{"kind":"dev","methods":{"agentStatus(address)":{"details":"Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud, but their status is not updated to Slashed yet.","params":{"agent":"Agent address"},"returns":{"_0":"Status for the given agent: (flag, domain, index)."}},"disputeStatus(address)":{"details":"Every returned value will be set to zero if agent was not slashed and is not in Dispute. `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.","params":{"agent":"Agent address"},"returns":{"disputePtr":"  Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.","flag":"        Flag describing the current Dispute status for the agent: None/Pending/Slashed","fraudProver":" Address who provided fraud proof to resolve the Dispute","rival":"       Address of the rival agent in the Dispute"}},"getAgent(uint256)":{"details":"Will return empty values if agent with given index doesn't exist.","params":{"index":"Agent index in the Agent Merkle Tree"},"returns":{"agent":"   Agent address","status":"  Status for the given agent: (flag, domain, index)"}},"getDispute(uint256)":{"details":"Will revert if dispute with given index hasn't been opened yet.","params":{"index":"Dispute index"},"returns":{"fraudProver":"     Address who provided fraud proof to resolve the Dispute","guard":"           Address of the Guard in the Dispute","notary":"          Address of the Notary in the Dispute","reportPayload":"   Raw payload with report data that led to the Dispute","reportSignature":" Guard signature for the report payload","slashedAgent":"    Address of the Agent who was slashed when Dispute was resolved"}},"getDisputesAmount()":{"details":"This includes the Disputes that have been resolved already."},"openDispute(uint32,uint32)":{"params":{"guardIndex":"Index of the Guard in the Agent Merkle Tree","notaryIndex":"Index of the Notary in the Agent Merkle Tree"}},"slashAgent(uint32,address,address)":{"params":{"agent":"Address of the Agent","domain":"Domain where the Agent is active","prover":"Address that initially provided fraud proof"}}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"agentRoot\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"agentStatus\",\"outputs\":[{\"components\":[{\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"index\",\"type\":\"uint32\"}],\"internalType\":\"struct AgentStatus\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"disputeStatus\",\"outputs\":[{\"internalType\":\"enum DisputeFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"address\",\"name\":\"rival\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"fraudProver\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"disputePtr\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getAgent\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"index\",\"type\":\"uint32\"}],\"internalType\":\"struct AgentStatus\",\"name\":\"status\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getDispute\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"guard\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"notary\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"slashedAgent\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"fraudProver\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"reportPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"reportSignature\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getDisputesAmount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"guardIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"notaryIndex\",\"type\":\"uint32\"}],\"name\":\"openDispute\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"prover\",\"type\":\"address\"}],\"name\":\"slashAgent\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"agentStatus(address)\":{\"details\":\"Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud, but their status is not updated to Slashed yet.\",\"params\":{\"agent\":\"Agent address\"},\"returns\":{\"_0\":\"Status for the given agent: (flag, domain, index).\"}},\"disputeStatus(address)\":{\"details\":\"Every returned value will be set to zero if agent was not slashed and is not in Dispute. `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\",\"params\":{\"agent\":\"Agent address\"},\"returns\":{\"disputePtr\":\"  Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\",\"flag\":\"        Flag describing the current Dispute status for the agent: None/Pending/Slashed\",\"fraudProver\":\" Address who provided fraud proof to resolve the Dispute\",\"rival\":\"       Address of the rival agent in the Dispute\"}},\"getAgent(uint256)\":{\"details\":\"Will return empty values if agent with given index doesn't exist.\",\"params\":{\"index\":\"Agent index in the Agent Merkle Tree\"},\"returns\":{\"agent\":\"   Agent address\",\"status\":\"  Status for the given agent: (flag, domain, index)\"}},\"getDispute(uint256)\":{\"details\":\"Will revert if dispute with given index hasn't been opened yet.\",\"params\":{\"index\":\"Dispute index\"},\"returns\":{\"fraudProver\":\"     Address who provided fraud proof to resolve the Dispute\",\"guard\":\"           Address of the Guard in the Dispute\",\"notary\":\"          Address of the Notary in the Dispute\",\"reportPayload\":\"   Raw payload with report data that led to the Dispute\",\"reportSignature\":\" Guard signature for the report payload\",\"slashedAgent\":\"    Address of the Agent who was slashed when Dispute was resolved\"}},\"getDisputesAmount()\":{\"details\":\"This includes the Disputes that have been resolved already.\"},\"openDispute(uint32,uint32)\":{\"params\":{\"guardIndex\":\"Index of the Guard in the Agent Merkle Tree\",\"notaryIndex\":\"Index of the Notary in the Agent Merkle Tree\"}},\"slashAgent(uint32,address,address)\":{\"params\":{\"agent\":\"Address of the Agent\",\"domain\":\"Domain where the Agent is active\",\"prover\":\"Address that initially provided fraud proof\"}}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"agentRoot()\":{\"notice\":\"Returns the latest known root of the Agent Merkle Tree.\"},\"agentStatus(address)\":{\"notice\":\"Returns (flag, domain, index) for a given agent. See Structures.sol for details.\"},\"disputeStatus(address)\":{\"notice\":\"Returns the current Dispute status of a given agent. See Structures.sol for details.\"},\"getAgent(uint256)\":{\"notice\":\"Returns agent address and their current status for a given agent index.\"},\"getDispute(uint256)\":{\"notice\":\"Returns information about the dispute with the given index.\"},\"getDisputesAmount()\":{\"notice\":\"Returns the number of opened Disputes.\"},\"openDispute(uint32,uint32)\":{\"notice\":\"Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Guard or Notary is already in Dispute.\"},\"slashAgent(uint32,address,address)\":{\"notice\":\"Allows Inbox to slash an agent, if their fraud was proven. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Domain doesn't match the saved agent domain.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"IAgentManager\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"agentRoot()":"36cba43c","agentStatus(address)":"28f3fac9","disputeStatus(address)":"3463d1b1","getAgent(uint256)":"2de5aaf7","getDispute(uint256)":"e3a96cbd","getDisputesAmount()":"3aaeccc6","openDispute(uint32,uint32)":"a2155c34","slashAgent(uint32,address,address)":"2853a0e6"}},"solidity/LightManager.sol:IAgentSecured":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"inputs":[],"name":"agentManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"}],"name":"agentStatus","outputs":[{"components":[{"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"uint32","name":"index","type":"uint32"}],"internalType":"struct AgentStatus","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getAgent","outputs":[{"internalType":"address","name":"agent","type":"address"},{"components":[{"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"uint32","name":"index","type":"uint32"}],"internalType":"struct AgentStatus","name":"status","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"inbox","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"agentIndex","type":"uint32"}],"name":"latestDisputeStatus","outputs":[{"components":[{"internalType":"enum DisputeFlag","name":"flag","type":"uint8"},{"internalType":"uint40","name":"openedAt","type":"uint40"},{"internalType":"uint40","name":"resolvedAt","type":"uint40"}],"internalType":"struct DisputeStatus","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"guardIndex","type":"uint32"},{"internalType":"uint32","name":"notaryIndex","type":"uint32"}],"name":"openDispute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"slashedIndex","type":"uint32"},{"internalType":"uint32","name":"rivalIndex","type":"uint32"}],"name":"resolveDispute","outputs":[],"stateMutability":"nonpayable","type":"function"}],"userDoc":{"kind":"user","methods":{"agentManager()":{"notice":"Returns the address of the local AgentManager contract, which is treated as the \"source of truth\" for agent statuses."},"agentStatus(address)":{"notice":"Returns (flag, domain, index) for a given agent. See Structures.sol for details."},"getAgent(uint256)":{"notice":"Returns agent address and their current status for a given agent index."},"inbox()":{"notice":"Returns the address of the local Inbox contract, which is treated as the \"source of truth\" for agent-signed statements."},"latestDisputeStatus(uint32)":{"notice":"Returns (flag, openedAt, resolvedAt) that describes the latest status of the latest dispute for an agent with a given index."},"openDispute(uint32,uint32)":{"notice":"Local AgentManager should call this function to indicate that a dispute between a Guard and a Notary has been opened."},"resolveDispute(uint32,uint32)":{"notice":"Local AgentManager should call this function to indicate that a dispute has been resolved due to one of the agents being slashed. \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute."}},"version":1},"developerDoc":{"kind":"dev","methods":{"agentStatus(address)":{"details":"Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud, but their status is not updated to Slashed yet.","params":{"agent":"Agent address"},"returns":{"_0":"Status for the given agent: (flag, domain, index)."}},"getAgent(uint256)":{"details":"Will return empty values if agent with given index doesn't exist.","params":{"index":"Agent index in the Agent Merkle Tree"},"returns":{"agent":"   Agent address","status":"  Status for the given agent: (flag, domain, index)"}},"inbox()":{"details":"Inbox passes verified agent statements to `IAgentSecured` contract."},"latestDisputeStatus(uint32)":{"details":"Will return empty values if agent with given index doesn't exist.","params":{"agentIndex":"Agent index in the Agent Merkle Tree"},"returns":{"_0":"Latest dispute status for the given agent: (flag, openedAt, resolvedAt)"}},"openDispute(uint32,uint32)":{"params":{"guardIndex":"Index of the Guard in the Agent Merkle Tree","notaryIndex":"Index of the Notary in the Agent Merkle Tree"}},"resolveDispute(uint32,uint32)":{"params":{"rivalIndex":"Index of the their Dispute Rival in the Agent Merkle Tree","slashedIndex":"Index of the slashed agent in the Agent Merkle Tree"}}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"agentManager\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"agentStatus\",\"outputs\":[{\"components\":[{\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"index\",\"type\":\"uint32\"}],\"internalType\":\"struct AgentStatus\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getAgent\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"index\",\"type\":\"uint32\"}],\"internalType\":\"struct AgentStatus\",\"name\":\"status\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"inbox\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"agentIndex\",\"type\":\"uint32\"}],\"name\":\"latestDisputeStatus\",\"outputs\":[{\"components\":[{\"internalType\":\"enum DisputeFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"uint40\",\"name\":\"openedAt\",\"type\":\"uint40\"},{\"internalType\":\"uint40\",\"name\":\"resolvedAt\",\"type\":\"uint40\"}],\"internalType\":\"struct DisputeStatus\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"guardIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"notaryIndex\",\"type\":\"uint32\"}],\"name\":\"openDispute\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"slashedIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"rivalIndex\",\"type\":\"uint32\"}],\"name\":\"resolveDispute\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"agentStatus(address)\":{\"details\":\"Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud, but their status is not updated to Slashed yet.\",\"params\":{\"agent\":\"Agent address\"},\"returns\":{\"_0\":\"Status for the given agent: (flag, domain, index).\"}},\"getAgent(uint256)\":{\"details\":\"Will return empty values if agent with given index doesn't exist.\",\"params\":{\"index\":\"Agent index in the Agent Merkle Tree\"},\"returns\":{\"agent\":\"   Agent address\",\"status\":\"  Status for the given agent: (flag, domain, index)\"}},\"inbox()\":{\"details\":\"Inbox passes verified agent statements to `IAgentSecured` contract.\"},\"latestDisputeStatus(uint32)\":{\"details\":\"Will return empty values if agent with given index doesn't exist.\",\"params\":{\"agentIndex\":\"Agent index in the Agent Merkle Tree\"},\"returns\":{\"_0\":\"Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\"}},\"openDispute(uint32,uint32)\":{\"params\":{\"guardIndex\":\"Index of the Guard in the Agent Merkle Tree\",\"notaryIndex\":\"Index of the Notary in the Agent Merkle Tree\"}},\"resolveDispute(uint32,uint32)\":{\"params\":{\"rivalIndex\":\"Index of the their Dispute Rival in the Agent Merkle Tree\",\"slashedIndex\":\"Index of the slashed agent in the Agent Merkle Tree\"}}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"agentManager()\":{\"notice\":\"Returns the address of the local AgentManager contract, which is treated as the \\\"source of truth\\\" for agent statuses.\"},\"agentStatus(address)\":{\"notice\":\"Returns (flag, domain, index) for a given agent. See Structures.sol for details.\"},\"getAgent(uint256)\":{\"notice\":\"Returns agent address and their current status for a given agent index.\"},\"inbox()\":{\"notice\":\"Returns the address of the local Inbox contract, which is treated as the \\\"source of truth\\\" for agent-signed statements.\"},\"latestDisputeStatus(uint32)\":{\"notice\":\"Returns (flag, openedAt, resolvedAt) that describes the latest status of the latest dispute for an agent with a given index.\"},\"openDispute(uint32,uint32)\":{\"notice\":\"Local AgentManager should call this function to indicate that a dispute between a Guard and a Notary has been opened.\"},\"resolveDispute(uint32,uint32)\":{\"notice\":\"Local AgentManager should call this function to indicate that a dispute has been resolved due to one of the agents being slashed. \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"IAgentSecured\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"agentManager()":"7622f78d","agentStatus(address)":"28f3fac9","getAgent(uint256)":"2de5aaf7","inbox()":"fb0e722b","latestDisputeStatus(uint32)":"dfadd81a","openDispute(uint32,uint32)":"a2155c34","resolveDispute(uint32,uint32)":"61169218"}},"solidity/LightManager.sol:IStatementInbox":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getGuardReport","outputs":[{"internalType":"bytes","name":"statementPayload","type":"bytes"},{"internalType":"bytes","name":"reportSignature","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getReportsAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getStoredSignature","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"stateIndex","type":"uint8"},{"internalType":"bytes","name":"srSignature","type":"bytes"},{"internalType":"bytes","name":"snapPayload","type":"bytes"},{"internalType":"bytes","name":"attPayload","type":"bytes"},{"internalType":"bytes","name":"attSignature","type":"bytes"}],"name":"submitStateReportWithAttestation","outputs":[{"internalType":"bool","name":"wasAccepted","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"stateIndex","type":"uint8"},{"internalType":"bytes","name":"srSignature","type":"bytes"},{"internalType":"bytes","name":"snapPayload","type":"bytes"},{"internalType":"bytes","name":"snapSignature","type":"bytes"}],"name":"submitStateReportWithSnapshot","outputs":[{"internalType":"bool","name":"wasAccepted","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"stateIndex","type":"uint8"},{"internalType":"bytes","name":"statePayload","type":"bytes"},{"internalType":"bytes","name":"srSignature","type":"bytes"},{"internalType":"bytes32[]","name":"snapProof","type":"bytes32[]"},{"internalType":"bytes","name":"attPayload","type":"bytes"},{"internalType":"bytes","name":"attSignature","type":"bytes"}],"name":"submitStateReportWithSnapshotProof","outputs":[{"internalType":"bool","name":"wasAccepted","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"rcptPayload","type":"bytes"},{"internalType":"bytes","name":"rcptSignature","type":"bytes"}],"name":"verifyReceipt","outputs":[{"internalType":"bool","name":"isValidReceipt","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"rcptPayload","type":"bytes"},{"internalType":"bytes","name":"rrSignature","type":"bytes"}],"name":"verifyReceiptReport","outputs":[{"internalType":"bool","name":"isValidReport","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"statePayload","type":"bytes"},{"internalType":"bytes","name":"srSignature","type":"bytes"}],"name":"verifyStateReport","outputs":[{"internalType":"bool","name":"isValidReport","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"stateIndex","type":"uint8"},{"internalType":"bytes","name":"snapPayload","type":"bytes"},{"internalType":"bytes","name":"attPayload","type":"bytes"},{"internalType":"bytes","name":"attSignature","type":"bytes"}],"name":"verifyStateWithAttestation","outputs":[{"internalType":"bool","name":"isValidState","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"stateIndex","type":"uint8"},{"internalType":"bytes","name":"snapPayload","type":"bytes"},{"internalType":"bytes","name":"snapSignature","type":"bytes"}],"name":"verifyStateWithSnapshot","outputs":[{"internalType":"bool","name":"isValidState","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"stateIndex","type":"uint8"},{"internalType":"bytes","name":"statePayload","type":"bytes"},{"internalType":"bytes32[]","name":"snapProof","type":"bytes32[]"},{"internalType":"bytes","name":"attPayload","type":"bytes"},{"internalType":"bytes","name":"attSignature","type":"bytes"}],"name":"verifyStateWithSnapshotProof","outputs":[{"internalType":"bool","name":"isValidState","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"userDoc":{"kind":"user","methods":{"getGuardReport(uint256)":{"notice":"Returns the Guard report with the given index stored in StatementInbox. \u003e Only reports that led to opening a Dispute are stored."},"getReportsAmount()":{"notice":"Returns the amount of Guard Reports stored in StatementInbox. \u003e Only reports that led to opening a Dispute are stored."},"getStoredSignature(uint256)":{"notice":"Returns the signature with the given index stored in StatementInbox."},"submitStateReportWithAttestation(uint8,bytes,bytes,bytes,bytes)":{"notice":"Accepts a Guard's state report signature, a Snapshot containing the reported State, as well as Notary signature for the Attestation created from this Snapshot. \u003e StateReport is a Guard statement saying \"Reported state is invalid\". - This results in an opened Dispute between the Guard and the Notary. - Note: Guard could (but doesn't have to) form a StateReport and use other values from `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin. \u003e Will revert if any of these is true: \u003e - State Report signer is not an active Guard. \u003e - Snapshot payload is not properly formatted. \u003e - State index is out of range. \u003e - Attestation payload is not properly formatted. \u003e - Attestation signer is not an active Notary. \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot. \u003e - The Guard or the Notary are already in a Dispute"},"submitStateReportWithSnapshot(uint8,bytes,bytes,bytes)":{"notice":"Accepts a Guard's state report signature, a Snapshot containing the reported State, as well as Notary signature for the Snapshot. \u003e StateReport is a Guard statement saying \"Reported state is invalid\". - This results in an opened Dispute between the Guard and the Notary. - Note: Guard could (but doesn't have to) form a StateReport and use other values from `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin. \u003e Will revert if any of these is true: \u003e - State Report signer is not an active Guard. \u003e - Snapshot payload is not properly formatted. \u003e - Snapshot signer is not an active Notary. \u003e - State index is out of range. \u003e - The Guard or the Notary are already in a Dispute"},"submitStateReportWithSnapshotProof(uint8,bytes,bytes,bytes32[],bytes,bytes)":{"notice":"Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation, as well as Notary signature for the Attestation. \u003e StateReport is a Guard statement saying \"Reported state is invalid\". - This results in an opened Dispute between the Guard and the Notary. - Note: Guard could (but doesn't have to) form a StateReport and use other values from `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin. \u003e Will revert if any of these is true: \u003e - State payload is not properly formatted. \u003e - State Report signer is not an active Guard. \u003e - Attestation payload is not properly formatted. \u003e - Attestation signer is not an active Notary. \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof. \u003e - Snapshot Proof's first element does not match the State metadata. \u003e - Snapshot Proof length exceeds Snapshot Tree Height. \u003e - State index is out of range. \u003e - The Guard or the Notary are already in a Dispute"},"verifyReceipt(bytes,bytes)":{"notice":"Verifies a message receipt signed by the Notary. - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message). - Slashes the Notary, if the receipt is invalid. \u003e Will revert if any of these is true: \u003e - Receipt payload is not properly formatted. \u003e - Receipt signer is not an active Notary. \u003e - Receipt's destination chain does not refer to this chain."},"verifyReceiptReport(bytes,bytes)":{"notice":"Verifies a Guard's receipt report signature. - Does nothing, if the report is valid (if the reported receipt is invalid). - Slashes the Guard, if the report is invalid (if the reported receipt is valid). \u003e Will revert if any of these is true: \u003e - Receipt payload is not properly formatted. \u003e - Receipt Report signer is not an active Guard. \u003e - Receipt does not refer to this chain."},"verifyStateReport(bytes,bytes)":{"notice":"Verifies a Guard's state report signature.  - Does nothing, if the report is valid (if the reported state is invalid).  - Slashes the Guard, if the report is invalid (if the reported state is valid). \u003e Will revert if any of these is true: \u003e - State payload is not properly formatted. \u003e - State Report signer is not an active Guard. \u003e - Reported State does not refer to this chain."},"verifyStateWithAttestation(uint8,bytes,bytes,bytes)":{"notice":"Verifies a state from the snapshot, that was used for the Notary-signed attestation. - Does nothing, if the state is valid (matches the historical state of this contract). - Slashes the Notary, if the state is invalid. \u003e Will revert if any of these is true: \u003e - Attestation payload is not properly formatted. \u003e - Attestation signer is not an active Notary. \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot. \u003e - Snapshot payload is not properly formatted. \u003e - State index is out of range. \u003e - State does not refer to this chain."},"verifyStateWithSnapshot(uint8,bytes,bytes)":{"notice":"Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary. - Does nothing, if the state is valid (matches the historical state of this contract). - Slashes the Agent, if the state is invalid. \u003e Will revert if any of these is true: \u003e - Snapshot payload is not properly formatted. \u003e - Snapshot signer is not an active Agent. \u003e - State index is out of range. \u003e - State does not refer to this chain."},"verifyStateWithSnapshotProof(uint8,bytes,bytes32[],bytes,bytes)":{"notice":"Verifies a state from the snapshot, that was used for the Notary-signed attestation. - Does nothing, if the state is valid (matches the historical state of this contract). - Slashes the Notary, if the state is invalid. \u003e Will revert if any of these is true: \u003e - Attestation payload is not properly formatted. \u003e - Attestation signer is not an active Notary. \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof. \u003e - Snapshot Proof's first element does not match the State metadata. \u003e - Snapshot Proof length exceeds Snapshot Tree Height. \u003e - State payload is not properly formatted. \u003e - State index is out of range. \u003e - State does not refer to this chain."}},"version":1},"developerDoc":{"kind":"dev","methods":{"getGuardReport(uint256)":{"details":"Will revert if report with given index doesn't exist.","params":{"index":"Report index"},"returns":{"reportSignature":" Guard signature for the report","statementPayload":"Raw payload with statement that Guard reported as invalid"}},"getStoredSignature(uint256)":{"details":"Will revert if signature with given index doesn't exist.","params":{"index":"Signature index"},"returns":{"_0":"Raw payload with signature"}},"submitStateReportWithAttestation(uint8,bytes,bytes,bytes,bytes)":{"params":{"attPayload":"Raw payload with Attestation data","attSignature":"Notary signature for the Attestation","snapPayload":"Raw payload with Snapshot data","srSignature":"Guard signature for the report","stateIndex":"Index of the reported State in the Snapshot"},"returns":{"wasAccepted":"     Whether the Report was accepted (resulting in Dispute between the agents)"}},"submitStateReportWithSnapshot(uint8,bytes,bytes,bytes)":{"params":{"snapPayload":"Raw payload with Snapshot data","snapSignature":"Notary signature for the Snapshot","srSignature":"Guard signature for the report","stateIndex":"Index of the reported State in the Snapshot"},"returns":{"wasAccepted":"     Whether the Report was accepted (resulting in Dispute between the agents)"}},"submitStateReportWithSnapshotProof(uint8,bytes,bytes,bytes32[],bytes,bytes)":{"params":{"attPayload":"Raw payload with Attestation data","attSignature":"Notary signature for the Attestation","snapProof":"Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree","srSignature":"Guard signature for the report","stateIndex":"Index of the reported State in the Snapshot","statePayload":"Raw payload with State data that Guard reports as invalid"},"returns":{"wasAccepted":"     Whether the Report was accepted (resulting in Dispute between the agents)"}},"verifyReceipt(bytes,bytes)":{"params":{"rcptPayload":"Raw payload with Receipt data","rcptSignature":"Notary signature for the receipt"},"returns":{"isValidReceipt":"  Whether the provided receipt is valid.                          Notary is slashed, if return value is FALSE."}},"verifyReceiptReport(bytes,bytes)":{"params":{"rcptPayload":"Raw payload with Receipt data that Guard reports as invalid","rrSignature":"Guard signature for the report"},"returns":{"isValidReport":"   Whether the provided report is valid.                          Guard is slashed, if return value is FALSE."}},"verifyStateReport(bytes,bytes)":{"params":{"srSignature":"Guard signature for the report","statePayload":"Raw payload with State data that Guard reports as invalid"},"returns":{"isValidReport":"   Whether the provided report is valid.                          Guard is slashed, if return value is FALSE."}},"verifyStateWithAttestation(uint8,bytes,bytes,bytes)":{"params":{"attPayload":"Raw payload with Attestation data","attSignature":"Notary signature for the attestation","snapPayload":"Raw payload with snapshot data","stateIndex":"State index to check"},"returns":{"isValidState":"    Whether the provided state is valid.                          Notary is slashed, if return value is FALSE."}},"verifyStateWithSnapshot(uint8,bytes,bytes)":{"params":{"snapPayload":"Raw payload with snapshot data","snapSignature":"Agent signature for the snapshot","stateIndex":"State index to check"},"returns":{"isValidState":"    Whether the provided state is valid.                          Agent is slashed, if return value is FALSE."}},"verifyStateWithSnapshotProof(uint8,bytes,bytes32[],bytes,bytes)":{"params":{"attPayload":"Raw payload with Attestation data","attSignature":"Notary signature for the attestation","snapProof":"Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree","stateIndex":"Index of state in the snapshot","statePayload":"Raw payload with State data to check"},"returns":{"isValidState":"    Whether the provided state is valid.                          Notary is slashed, if return value is FALSE."}}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getGuardReport\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"statementPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"reportSignature\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getReportsAmount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getStoredSignature\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"stateIndex\",\"type\":\"uint8\"},{\"internalType\":\"bytes\",\"name\":\"srSignature\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"snapPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"attPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"attSignature\",\"type\":\"bytes\"}],\"name\":\"submitStateReportWithAttestation\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"wasAccepted\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"stateIndex\",\"type\":\"uint8\"},{\"internalType\":\"bytes\",\"name\":\"srSignature\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"snapPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"snapSignature\",\"type\":\"bytes\"}],\"name\":\"submitStateReportWithSnapshot\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"wasAccepted\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"stateIndex\",\"type\":\"uint8\"},{\"internalType\":\"bytes\",\"name\":\"statePayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"srSignature\",\"type\":\"bytes\"},{\"internalType\":\"bytes32[]\",\"name\":\"snapProof\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes\",\"name\":\"attPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"attSignature\",\"type\":\"bytes\"}],\"name\":\"submitStateReportWithSnapshotProof\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"wasAccepted\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"rcptPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"rcptSignature\",\"type\":\"bytes\"}],\"name\":\"verifyReceipt\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"isValidReceipt\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"rcptPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"rrSignature\",\"type\":\"bytes\"}],\"name\":\"verifyReceiptReport\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"isValidReport\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"statePayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"srSignature\",\"type\":\"bytes\"}],\"name\":\"verifyStateReport\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"isValidReport\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"stateIndex\",\"type\":\"uint8\"},{\"internalType\":\"bytes\",\"name\":\"snapPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"attPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"attSignature\",\"type\":\"bytes\"}],\"name\":\"verifyStateWithAttestation\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"isValidState\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"stateIndex\",\"type\":\"uint8\"},{\"internalType\":\"bytes\",\"name\":\"snapPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"snapSignature\",\"type\":\"bytes\"}],\"name\":\"verifyStateWithSnapshot\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"isValidState\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"stateIndex\",\"type\":\"uint8\"},{\"internalType\":\"bytes\",\"name\":\"statePayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes32[]\",\"name\":\"snapProof\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes\",\"name\":\"attPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"attSignature\",\"type\":\"bytes\"}],\"name\":\"verifyStateWithSnapshotProof\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"isValidState\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"getGuardReport(uint256)\":{\"details\":\"Will revert if report with given index doesn't exist.\",\"params\":{\"index\":\"Report index\"},\"returns\":{\"reportSignature\":\" Guard signature for the report\",\"statementPayload\":\"Raw payload with statement that Guard reported as invalid\"}},\"getStoredSignature(uint256)\":{\"details\":\"Will revert if signature with given index doesn't exist.\",\"params\":{\"index\":\"Signature index\"},\"returns\":{\"_0\":\"Raw payload with signature\"}},\"submitStateReportWithAttestation(uint8,bytes,bytes,bytes,bytes)\":{\"params\":{\"attPayload\":\"Raw payload with Attestation data\",\"attSignature\":\"Notary signature for the Attestation\",\"snapPayload\":\"Raw payload with Snapshot data\",\"srSignature\":\"Guard signature for the report\",\"stateIndex\":\"Index of the reported State in the Snapshot\"},\"returns\":{\"wasAccepted\":\"     Whether the Report was accepted (resulting in Dispute between the agents)\"}},\"submitStateReportWithSnapshot(uint8,bytes,bytes,bytes)\":{\"params\":{\"snapPayload\":\"Raw payload with Snapshot data\",\"snapSignature\":\"Notary signature for the Snapshot\",\"srSignature\":\"Guard signature for the report\",\"stateIndex\":\"Index of the reported State in the Snapshot\"},\"returns\":{\"wasAccepted\":\"     Whether the Report was accepted (resulting in Dispute between the agents)\"}},\"submitStateReportWithSnapshotProof(uint8,bytes,bytes,bytes32[],bytes,bytes)\":{\"params\":{\"attPayload\":\"Raw payload with Attestation data\",\"attSignature\":\"Notary signature for the Attestation\",\"snapProof\":\"Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\",\"srSignature\":\"Guard signature for the report\",\"stateIndex\":\"Index of the reported State in the Snapshot\",\"statePayload\":\"Raw payload with State data that Guard reports as invalid\"},\"returns\":{\"wasAccepted\":\"     Whether the Report was accepted (resulting in Dispute between the agents)\"}},\"verifyReceipt(bytes,bytes)\":{\"params\":{\"rcptPayload\":\"Raw payload with Receipt data\",\"rcptSignature\":\"Notary signature for the receipt\"},\"returns\":{\"isValidReceipt\":\"  Whether the provided receipt is valid.                          Notary is slashed, if return value is FALSE.\"}},\"verifyReceiptReport(bytes,bytes)\":{\"params\":{\"rcptPayload\":\"Raw payload with Receipt data that Guard reports as invalid\",\"rrSignature\":\"Guard signature for the report\"},\"returns\":{\"isValidReport\":\"   Whether the provided report is valid.                          Guard is slashed, if return value is FALSE.\"}},\"verifyStateReport(bytes,bytes)\":{\"params\":{\"srSignature\":\"Guard signature for the report\",\"statePayload\":\"Raw payload with State data that Guard reports as invalid\"},\"returns\":{\"isValidReport\":\"   Whether the provided report is valid.                          Guard is slashed, if return value is FALSE.\"}},\"verifyStateWithAttestation(uint8,bytes,bytes,bytes)\":{\"params\":{\"attPayload\":\"Raw payload with Attestation data\",\"attSignature\":\"Notary signature for the attestation\",\"snapPayload\":\"Raw payload with snapshot data\",\"stateIndex\":\"State index to check\"},\"returns\":{\"isValidState\":\"    Whether the provided state is valid.                          Notary is slashed, if return value is FALSE.\"}},\"verifyStateWithSnapshot(uint8,bytes,bytes)\":{\"params\":{\"snapPayload\":\"Raw payload with snapshot data\",\"snapSignature\":\"Agent signature for the snapshot\",\"stateIndex\":\"State index to check\"},\"returns\":{\"isValidState\":\"    Whether the provided state is valid.                          Agent is slashed, if return value is FALSE.\"}},\"verifyStateWithSnapshotProof(uint8,bytes,bytes32[],bytes,bytes)\":{\"params\":{\"attPayload\":\"Raw payload with Attestation data\",\"attSignature\":\"Notary signature for the attestation\",\"snapProof\":\"Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\",\"stateIndex\":\"Index of state in the snapshot\",\"statePayload\":\"Raw payload with State data to check\"},\"returns\":{\"isValidState\":\"    Whether the provided state is valid.                          Notary is slashed, if return value is FALSE.\"}}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"getGuardReport(uint256)\":{\"notice\":\"Returns the Guard report with the given index stored in StatementInbox. \u003e Only reports that led to opening a Dispute are stored.\"},\"getReportsAmount()\":{\"notice\":\"Returns the amount of Guard Reports stored in StatementInbox. \u003e Only reports that led to opening a Dispute are stored.\"},\"getStoredSignature(uint256)\":{\"notice\":\"Returns the signature with the given index stored in StatementInbox.\"},\"submitStateReportWithAttestation(uint8,bytes,bytes,bytes,bytes)\":{\"notice\":\"Accepts a Guard's state report signature, a Snapshot containing the reported State, as well as Notary signature for the Attestation created from this Snapshot. \u003e StateReport is a Guard statement saying \\\"Reported state is invalid\\\". - This results in an opened Dispute between the Guard and the Notary. - Note: Guard could (but doesn't have to) form a StateReport and use other values from `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin. \u003e Will revert if any of these is true: \u003e - State Report signer is not an active Guard. \u003e - Snapshot payload is not properly formatted. \u003e - State index is out of range. \u003e - Attestation payload is not properly formatted. \u003e - Attestation signer is not an active Notary. \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot. \u003e - The Guard or the Notary are already in a Dispute\"},\"submitStateReportWithSnapshot(uint8,bytes,bytes,bytes)\":{\"notice\":\"Accepts a Guard's state report signature, a Snapshot containing the reported State, as well as Notary signature for the Snapshot. \u003e StateReport is a Guard statement saying \\\"Reported state is invalid\\\". - This results in an opened Dispute between the Guard and the Notary. - Note: Guard could (but doesn't have to) form a StateReport and use other values from `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin. \u003e Will revert if any of these is true: \u003e - State Report signer is not an active Guard. \u003e - Snapshot payload is not properly formatted. \u003e - Snapshot signer is not an active Notary. \u003e - State index is out of range. \u003e - The Guard or the Notary are already in a Dispute\"},\"submitStateReportWithSnapshotProof(uint8,bytes,bytes,bytes32[],bytes,bytes)\":{\"notice\":\"Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation, as well as Notary signature for the Attestation. \u003e StateReport is a Guard statement saying \\\"Reported state is invalid\\\". - This results in an opened Dispute between the Guard and the Notary. - Note: Guard could (but doesn't have to) form a StateReport and use other values from `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin. \u003e Will revert if any of these is true: \u003e - State payload is not properly formatted. \u003e - State Report signer is not an active Guard. \u003e - Attestation payload is not properly formatted. \u003e - Attestation signer is not an active Notary. \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof. \u003e - Snapshot Proof's first element does not match the State metadata. \u003e - Snapshot Proof length exceeds Snapshot Tree Height. \u003e - State index is out of range. \u003e - The Guard or the Notary are already in a Dispute\"},\"verifyReceipt(bytes,bytes)\":{\"notice\":\"Verifies a message receipt signed by the Notary. - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message). - Slashes the Notary, if the receipt is invalid. \u003e Will revert if any of these is true: \u003e - Receipt payload is not properly formatted. \u003e - Receipt signer is not an active Notary. \u003e - Receipt's destination chain does not refer to this chain.\"},\"verifyReceiptReport(bytes,bytes)\":{\"notice\":\"Verifies a Guard's receipt report signature. - Does nothing, if the report is valid (if the reported receipt is invalid). - Slashes the Guard, if the report is invalid (if the reported receipt is valid). \u003e Will revert if any of these is true: \u003e - Receipt payload is not properly formatted. \u003e - Receipt Report signer is not an active Guard. \u003e - Receipt does not refer to this chain.\"},\"verifyStateReport(bytes,bytes)\":{\"notice\":\"Verifies a Guard's state report signature.  - Does nothing, if the report is valid (if the reported state is invalid).  - Slashes the Guard, if the report is invalid (if the reported state is valid). \u003e Will revert if any of these is true: \u003e - State payload is not properly formatted. \u003e - State Report signer is not an active Guard. \u003e - Reported State does not refer to this chain.\"},\"verifyStateWithAttestation(uint8,bytes,bytes,bytes)\":{\"notice\":\"Verifies a state from the snapshot, that was used for the Notary-signed attestation. - Does nothing, if the state is valid (matches the historical state of this contract). - Slashes the Notary, if the state is invalid. \u003e Will revert if any of these is true: \u003e - Attestation payload is not properly formatted. \u003e - Attestation signer is not an active Notary. \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot. \u003e - Snapshot payload is not properly formatted. \u003e - State index is out of range. \u003e - State does not refer to this chain.\"},\"verifyStateWithSnapshot(uint8,bytes,bytes)\":{\"notice\":\"Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary. - Does nothing, if the state is valid (matches the historical state of this contract). - Slashes the Agent, if the state is invalid. \u003e Will revert if any of these is true: \u003e - Snapshot payload is not properly formatted. \u003e - Snapshot signer is not an active Agent. \u003e - State index is out of range. \u003e - State does not refer to this chain.\"},\"verifyStateWithSnapshotProof(uint8,bytes,bytes32[],bytes,bytes)\":{\"notice\":\"Verifies a state from the snapshot, that was used for the Notary-signed attestation. - Does nothing, if the state is valid (matches the historical state of this contract). - Slashes the Notary, if the state is invalid. \u003e Will revert if any of these is true: \u003e - Attestation payload is not properly formatted. \u003e - Attestation signer is not an active Notary. \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof. \u003e - Snapshot Proof's first element does not match the State metadata. \u003e - Snapshot Proof length exceeds Snapshot Tree Height. \u003e - State payload is not properly formatted. \u003e - State index is out of range. \u003e - State does not refer to this chain.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"IStatementInbox\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"getGuardReport(uint256)":"c495912b","getReportsAmount()":"756ed01d","getStoredSignature(uint256)":"ddeffa66","submitStateReportWithAttestation(uint8,bytes,bytes,bytes,bytes)":"243b9224","submitStateReportWithSnapshot(uint8,bytes,bytes,bytes)":"333138e2","submitStateReportWithSnapshotProof(uint8,bytes,bytes,bytes32[],bytes,bytes)":"be7e63da","verifyReceipt(bytes,bytes)":"c25aa585","verifyReceiptReport(bytes,bytes)":"91af2e5d","verifyStateReport(bytes,bytes)":"dfe39675","verifyStateWithAttestation(uint8,bytes,bytes,bytes)":"7d9978ae","verifyStateWithSnapshot(uint8,bytes,bytes)":"8671012e","verifyStateWithSnapshotProof(uint8,bytes,bytes32[],bytes,bytes)":"e3097af8"}},"solidity/LightManager.sol:Initializable":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"}],"userDoc":{"kind":"user","methods":{},"version":1},"developerDoc":{"custom:oz-upgrades-unsafe-allow":"constructor constructor() {     _disableInitializers(); } ``` ====","details":"This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. The initialization functions use a version number. Once a version number is used, it is consumed and cannot be reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in case an upgrade adds a module that needs to be initialized. For example: [.hljs-theme-light.nopadding] ```solidity contract MyToken is ERC20Upgradeable {     function initialize() initializer public {         __ERC20_init(\"MyToken\", \"MTK\");     } } contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {     function initializeV2() reinitializer(2) public {         __ERC20Permit_init(\"MyToken\");     } } ``` TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. [CAUTION] ==== Avoid leaving a contract uninitialized. An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: [.hljs-theme-light.nopadding] ```","events":{"Initialized(uint8)":{"details":"Triggered when the contract has been initialized or reinitialized."}},"kind":"dev","methods":{},"stateVariables":{"_initialized":{"custom:oz-retyped-from":"bool","details":"Indicates that the contract has been initialized."},"_initializing":{"details":"Indicates that the contract is in the process of being initialized."}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"version\",\"type\":\"uint8\"}],\"name\":\"Initialized\",\"type\":\"event\"}],\"devdoc\":{\"custom:oz-upgrades-unsafe-allow\":\"constructor constructor() {     _disableInitializers(); } ``` ====\",\"details\":\"This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. The initialization functions use a version number. Once a version number is used, it is consumed and cannot be reused. This mechanism prevents re-execution of each \\\"step\\\" but allows the creation of new initialization steps in case an upgrade adds a module that needs to be initialized. For example: [.hljs-theme-light.nopadding] ```solidity contract MyToken is ERC20Upgradeable {     function initialize() initializer public {         __ERC20_init(\\\"MyToken\\\", \\\"MTK\\\");     } } contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {     function initializeV2() reinitializer(2) public {         __ERC20Permit_init(\\\"MyToken\\\");     } } ``` TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. [CAUTION] ==== Avoid leaving a contract uninitialized. An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: [.hljs-theme-light.nopadding] ```\",\"events\":{\"Initialized(uint8)\":{\"details\":\"Triggered when the contract has been initialized or reinitialized.\"}},\"kind\":\"dev\",\"methods\":{},\"stateVariables\":{\"_initialized\":{\"custom:oz-retyped-from\":\"bool\",\"details\":\"Indicates that the contract has been initialized.\"},\"_initializing\":{\"details\":\"Indicates that the contract is in the process of being initialized.\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"Initializable\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{}},"solidity/LightManager.sol:InterfaceBondingManager":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"inputs":[{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"address","name":"agent","type":"address"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"addAgent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"}],"name":"agentLeaf","outputs":[{"internalType":"bytes32","name":"leaf","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allLeafs","outputs":[{"internalType":"bytes32[]","name":"leafs","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"address","name":"agent","type":"address"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"completeSlashing","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"address","name":"agent","type":"address"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"completeUnstaking","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"domain","type":"uint32"}],"name":"getActiveAgents","outputs":[{"internalType":"address[]","name":"agents","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"indexFrom","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getLeafs","outputs":[{"internalType":"bytes32[]","name":"leafs","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"}],"name":"getProof","outputs":[{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"address","name":"agent","type":"address"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"initiateUnstaking","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"leafsAmount","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"msgOrigin","type":"uint32"},{"internalType":"uint256","name":"proofMaturity","type":"uint256"},{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"address","name":"agent","type":"address"},{"internalType":"address","name":"prover","type":"address"}],"name":"remoteSlashAgent","outputs":[{"internalType":"bytes4","name":"magicValue","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"address","name":"slashedAgent","type":"address"}],"name":"resolveDisputeWhenStuck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint32","name":"origin","type":"uint32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawTips","outputs":[],"stateMutability":"nonpayable","type":"function"}],"userDoc":{"kind":"user","methods":{"addAgent(uint32,address,bytes32[])":{"notice":"Adds a new agent for the domain. This is either a fresh address (Inactive), or an agent who used to be active on the same domain before (Resting)."},"agentLeaf(address)":{"notice":"Returns a leaf representing the current status of agent in the Agent Merkle Tree."},"allLeafs()":{"notice":"Returns a full list of leafs from the Agent Merkle Tree."},"completeSlashing(uint32,address,bytes32[])":{"notice":"Completes the slashing of the agent bond. Agent signature is no longer considered valid under the updated Agent Merkle Root."},"completeUnstaking(uint32,address,bytes32[])":{"notice":"Completes the unstaking of the agent bond. Agent signature is no longer considered valid on any of the chains."},"getActiveAgents(uint32)":{"notice":"Returns all active agents for a given domain."},"getLeafs(uint256,uint256)":{"notice":"Returns a list of leafs from the Agent Merkle Tree with indexes [indexFrom .. indexFrom + amount)."},"getProof(address)":{"notice":"Returns a proof of inclusion of the agent in the Agent Merkle Tree."},"initiateUnstaking(uint32,address,bytes32[])":{"notice":"Initiates the unstaking of the agent bond. Agent signature is immediately no longer considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager updates their agent merkle root on these chains."},"leafsAmount()":{"notice":"Returns a total amount of leafs representing known agents."},"remoteSlashAgent(uint32,uint256,uint32,address,address)":{"notice":"Remote AgentManager should call this function to indicate that the agent has been proven to commit fraud on the origin chain."},"resolveDisputeWhenStuck(uint32,address)":{"notice":"Allows contract owner to resolve a stuck Dispute. This could only be called if no fresh data has been submitted by the Notaries to the Inbox, which is required for the Dispute to be resolved naturally. \u003e Will revert if any of these is true: \u003e - Caller is not contract owner. \u003e - Domain doesn't match the saved agent domain. \u003e - `slashedAgent` is not in Dispute. \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox."},"withdrawTips(address,uint32,uint256)":{"notice":"Withdraws locked base message tips from requested domain Origin to the recipient. Issues a call to a local Origin contract, or sends a manager message to the remote chain."}},"version":1},"developerDoc":{"kind":"dev","methods":{"addAgent(uint32,address,bytes32[])":{"details":"Inactive: `proof` should be the proof of inclusion of an empty leaf having index following the last added agent in the tree.Resting: `proof` should be the proof of inclusion of the agent leaf with Resting flag having index previously assigned to the agent.","params":{"agent":"Address of the Agent","domain":"Domain where the Agent will be active","proof":"Merkle proof of the Inactive/Resting status for the agent"}},"agentLeaf(address)":{"details":"Will return an empty leaf, if agent is not added to the tree yet.","params":{"agent":"Agent address"},"returns":{"leaf":"    Agent leaf in the Agent Merkle Tree"}},"allLeafs()":{"details":"This might consume a lot of gas, do not use this on-chain."},"completeSlashing(uint32,address,bytes32[])":{"details":"`proof` should be the proof of inclusion of the agent leaf with Active/Unstaking flag having index previously assigned to the agent.","params":{"agent":"Address of the Agent","domain":"Domain where the Agent was active","proof":"Merkle proof of the active/unstaking status for the agent"}},"completeUnstaking(uint32,address,bytes32[])":{"details":"`proof` should be the proof of inclusion of the agent leaf with Unstaking flag having index previously assigned to the agent.","params":{"agent":"Address of the Agent","domain":"Domain where the Agent was active","proof":"Merkle proof of the unstaking status for the agent"}},"getActiveAgents(uint32)":{"params":{"agents":"List of active agents for the domain","domain":"Domain to get agents from (ZERO for Guards)"}},"getLeafs(uint256,uint256)":{"details":"This might consume a lot of gas, do not use this on-chain.Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount"},"getProof(address)":{"details":"Will return a proof for an empty leaf, if agent is not added to the tree yet. This proof could be used by ANY next new agent that calls {addAgent}.This WILL consume a lot of gas, do not use this on-chain.The alternative way to create a proof is to fetch the full list of leafs using either {allLeafs} or {getLeafs}, and create a merkle proof from that.","params":{"agent":"Agent address"},"returns":{"proof":"   Merkle proof for the agent"}},"initiateUnstaking(uint32,address,bytes32[])":{"details":"`proof` should be the proof of inclusion of the agent leaf with Active flag having index previously assigned to the agent.","params":{"agent":"Address of the Agent","domain":"Domain where the Agent is active","proof":"Merkle proof of the Active status for the agent"}},"leafsAmount()":{"details":"This includes active, unstaking, resting and slashed agents. This also includes an empty leaf as the very first entry."},"remoteSlashAgent(uint32,uint256,uint32,address,address)":{"details":"This initiates the process of agent slashing. It could be immediately completed by anyone calling completeSlashing() providing a correct merkle proof for the OLD agent status. Note: as an extra security check this function returns its own selector, so that Destination could verify that a \"remote\" function was called when executing a manager message. Will revert if `msgOrigin` is equal to contract's local domain.","params":{"agent":"Address of the slashed Agent","domain":"Domain where the slashed agent was active","prover":"Address that initially provided fraud proof to remote AgentManager"},"returns":{"magicValue":"  Selector of this function"}},"resolveDisputeWhenStuck(uint32,address)":{"params":{"slashedAgent":"Agent that is being slashed"}},"withdrawTips(address,uint32,uint256)":{"details":"Could only be called by the Summit contract.","params":{"amount":"Tips value to withdraw","origin":"Domain where tips need to be withdrawn","recipient":"Address to withdraw tips to"}}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"internalType\":\"bytes32[]\",\"name\":\"proof\",\"type\":\"bytes32[]\"}],\"name\":\"addAgent\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"agentLeaf\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"leaf\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"allLeafs\",\"outputs\":[{\"internalType\":\"bytes32[]\",\"name\":\"leafs\",\"type\":\"bytes32[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"internalType\":\"bytes32[]\",\"name\":\"proof\",\"type\":\"bytes32[]\"}],\"name\":\"completeSlashing\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"internalType\":\"bytes32[]\",\"name\":\"proof\",\"type\":\"bytes32[]\"}],\"name\":\"completeUnstaking\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"}],\"name\":\"getActiveAgents\",\"outputs\":[{\"internalType\":\"address[]\",\"name\":\"agents\",\"type\":\"address[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"indexFrom\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"getLeafs\",\"outputs\":[{\"internalType\":\"bytes32[]\",\"name\":\"leafs\",\"type\":\"bytes32[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"getProof\",\"outputs\":[{\"internalType\":\"bytes32[]\",\"name\":\"proof\",\"type\":\"bytes32[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"internalType\":\"bytes32[]\",\"name\":\"proof\",\"type\":\"bytes32[]\"}],\"name\":\"initiateUnstaking\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"leafsAmount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"msgOrigin\",\"type\":\"uint32\"},{\"internalType\":\"uint256\",\"name\":\"proofMaturity\",\"type\":\"uint256\"},{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"prover\",\"type\":\"address\"}],\"name\":\"remoteSlashAgent\",\"outputs\":[{\"internalType\":\"bytes4\",\"name\":\"magicValue\",\"type\":\"bytes4\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"address\",\"name\":\"slashedAgent\",\"type\":\"address\"}],\"name\":\"resolveDisputeWhenStuck\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint32\",\"name\":\"origin\",\"type\":\"uint32\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"withdrawTips\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"addAgent(uint32,address,bytes32[])\":{\"details\":\"Inactive: `proof` should be the proof of inclusion of an empty leaf having index following the last added agent in the tree.Resting: `proof` should be the proof of inclusion of the agent leaf with Resting flag having index previously assigned to the agent.\",\"params\":{\"agent\":\"Address of the Agent\",\"domain\":\"Domain where the Agent will be active\",\"proof\":\"Merkle proof of the Inactive/Resting status for the agent\"}},\"agentLeaf(address)\":{\"details\":\"Will return an empty leaf, if agent is not added to the tree yet.\",\"params\":{\"agent\":\"Agent address\"},\"returns\":{\"leaf\":\"    Agent leaf in the Agent Merkle Tree\"}},\"allLeafs()\":{\"details\":\"This might consume a lot of gas, do not use this on-chain.\"},\"completeSlashing(uint32,address,bytes32[])\":{\"details\":\"`proof` should be the proof of inclusion of the agent leaf with Active/Unstaking flag having index previously assigned to the agent.\",\"params\":{\"agent\":\"Address of the Agent\",\"domain\":\"Domain where the Agent was active\",\"proof\":\"Merkle proof of the active/unstaking status for the agent\"}},\"completeUnstaking(uint32,address,bytes32[])\":{\"details\":\"`proof` should be the proof of inclusion of the agent leaf with Unstaking flag having index previously assigned to the agent.\",\"params\":{\"agent\":\"Address of the Agent\",\"domain\":\"Domain where the Agent was active\",\"proof\":\"Merkle proof of the unstaking status for the agent\"}},\"getActiveAgents(uint32)\":{\"params\":{\"agents\":\"List of active agents for the domain\",\"domain\":\"Domain to get agents from (ZERO for Guards)\"}},\"getLeafs(uint256,uint256)\":{\"details\":\"This might consume a lot of gas, do not use this on-chain.Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\"},\"getProof(address)\":{\"details\":\"Will return a proof for an empty leaf, if agent is not added to the tree yet. This proof could be used by ANY next new agent that calls {addAgent}.This WILL consume a lot of gas, do not use this on-chain.The alternative way to create a proof is to fetch the full list of leafs using either {allLeafs} or {getLeafs}, and create a merkle proof from that.\",\"params\":{\"agent\":\"Agent address\"},\"returns\":{\"proof\":\"   Merkle proof for the agent\"}},\"initiateUnstaking(uint32,address,bytes32[])\":{\"details\":\"`proof` should be the proof of inclusion of the agent leaf with Active flag having index previously assigned to the agent.\",\"params\":{\"agent\":\"Address of the Agent\",\"domain\":\"Domain where the Agent is active\",\"proof\":\"Merkle proof of the Active status for the agent\"}},\"leafsAmount()\":{\"details\":\"This includes active, unstaking, resting and slashed agents. This also includes an empty leaf as the very first entry.\"},\"remoteSlashAgent(uint32,uint256,uint32,address,address)\":{\"details\":\"This initiates the process of agent slashing. It could be immediately completed by anyone calling completeSlashing() providing a correct merkle proof for the OLD agent status. Note: as an extra security check this function returns its own selector, so that Destination could verify that a \\\"remote\\\" function was called when executing a manager message. Will revert if `msgOrigin` is equal to contract's local domain.\",\"params\":{\"agent\":\"Address of the slashed Agent\",\"domain\":\"Domain where the slashed agent was active\",\"prover\":\"Address that initially provided fraud proof to remote AgentManager\"},\"returns\":{\"magicValue\":\"  Selector of this function\"}},\"resolveDisputeWhenStuck(uint32,address)\":{\"params\":{\"slashedAgent\":\"Agent that is being slashed\"}},\"withdrawTips(address,uint32,uint256)\":{\"details\":\"Could only be called by the Summit contract.\",\"params\":{\"amount\":\"Tips value to withdraw\",\"origin\":\"Domain where tips need to be withdrawn\",\"recipient\":\"Address to withdraw tips to\"}}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"addAgent(uint32,address,bytes32[])\":{\"notice\":\"Adds a new agent for the domain. This is either a fresh address (Inactive), or an agent who used to be active on the same domain before (Resting).\"},\"agentLeaf(address)\":{\"notice\":\"Returns a leaf representing the current status of agent in the Agent Merkle Tree.\"},\"allLeafs()\":{\"notice\":\"Returns a full list of leafs from the Agent Merkle Tree.\"},\"completeSlashing(uint32,address,bytes32[])\":{\"notice\":\"Completes the slashing of the agent bond. Agent signature is no longer considered valid under the updated Agent Merkle Root.\"},\"completeUnstaking(uint32,address,bytes32[])\":{\"notice\":\"Completes the unstaking of the agent bond. Agent signature is no longer considered valid on any of the chains.\"},\"getActiveAgents(uint32)\":{\"notice\":\"Returns all active agents for a given domain.\"},\"getLeafs(uint256,uint256)\":{\"notice\":\"Returns a list of leafs from the Agent Merkle Tree with indexes [indexFrom .. indexFrom + amount).\"},\"getProof(address)\":{\"notice\":\"Returns a proof of inclusion of the agent in the Agent Merkle Tree.\"},\"initiateUnstaking(uint32,address,bytes32[])\":{\"notice\":\"Initiates the unstaking of the agent bond. Agent signature is immediately no longer considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager updates their agent merkle root on these chains.\"},\"leafsAmount()\":{\"notice\":\"Returns a total amount of leafs representing known agents.\"},\"remoteSlashAgent(uint32,uint256,uint32,address,address)\":{\"notice\":\"Remote AgentManager should call this function to indicate that the agent has been proven to commit fraud on the origin chain.\"},\"resolveDisputeWhenStuck(uint32,address)\":{\"notice\":\"Allows contract owner to resolve a stuck Dispute. This could only be called if no fresh data has been submitted by the Notaries to the Inbox, which is required for the Dispute to be resolved naturally. \u003e Will revert if any of these is true: \u003e - Caller is not contract owner. \u003e - Domain doesn't match the saved agent domain. \u003e - `slashedAgent` is not in Dispute. \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\"},\"withdrawTips(address,uint32,uint256)\":{\"notice\":\"Withdraws locked base message tips from requested domain Origin to the recipient. Issues a call to a local Origin contract, or sends a manager message to the remote chain.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"InterfaceBondingManager\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"addAgent(uint32,address,bytes32[])":"237a85a5","agentLeaf(address)":"c99dcb9e","allLeafs()":"12db2ef6","completeSlashing(uint32,address,bytes32[])":"fbc5265e","completeUnstaking(uint32,address,bytes32[])":"4c3e1c1f","getActiveAgents(uint32)":"c1c0f4f6","getLeafs(uint256,uint256)":"33d1b2e8","getProof(address)":"3eea79d1","initiateUnstaking(uint32,address,bytes32[])":"130c5673","leafsAmount()":"33c3a8f3","remoteSlashAgent(uint32,uint256,uint32,address,address)":"9d228a51","resolveDisputeWhenStuck(uint32,address)":"b15a707d","withdrawTips(address,uint32,uint256)":"cc875501"}},"solidity/LightManager.sol:InterfaceDestination":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"inputs":[{"internalType":"uint32","name":"notaryIndex","type":"uint32"},{"internalType":"uint256","name":"sigIndex","type":"uint256"},{"internalType":"bytes","name":"attPayload","type":"bytes"},{"internalType":"bytes32","name":"agentRoot","type":"bytes32"},{"internalType":"ChainGas[]","name":"snapGas","type":"uint128[]"}],"name":"acceptAttestation","outputs":[{"internalType":"bool","name":"wasAccepted","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"attestationsAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"destStatus","outputs":[{"internalType":"uint40","name":"snapRootTime","type":"uint40"},{"internalType":"uint40","name":"agentRootTime","type":"uint40"},{"internalType":"uint32","name":"notaryIndex","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getAttestation","outputs":[{"internalType":"bytes","name":"attPayload","type":"bytes"},{"internalType":"bytes","name":"attSignature","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"domain","type":"uint32"}],"name":"getGasData","outputs":[{"internalType":"GasData","name":"gasData","type":"uint96"},{"internalType":"uint256","name":"dataMaturity","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"notaryIndex","type":"uint32"}],"name":"lastAttestationNonce","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextAgentRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"passAgentRoot","outputs":[{"internalType":"bool","name":"rootPending","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"userDoc":{"kind":"user","methods":{"acceptAttestation(uint32,uint256,bytes,bytes32,uint128[])":{"notice":"Accepts an attestation, which local `AgentManager` verified to have been signed by an active Notary for this chain. \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain. - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree. - Messages coming from chains included in the Attestation's snapshot could be proven. - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken. \u003e Will revert if any of these is true: \u003e - Called by anyone other than local `AgentManager`. \u003e - Attestation payload is not properly formatted. \u003e - Attestation signer is in Dispute. \u003e - Attestation's snapshot root has been previously submitted. Note: agentRoot and snapGas have been verified by the local `AgentManager`."},"attestationsAmount()":{"notice":"Returns the total amount of Notaries attestations that have been accepted."},"destStatus()":{"notice":"Returns status of Destination contract as far as snapshot/agent roots are concerned"},"getAttestation(uint256)":{"notice":"Returns a Notary-signed attestation with a given index. \u003e Index refers to the list of all attestations accepted by this contract."},"getGasData(uint32)":{"notice":"Returns the gas data for a given chain from the latest accepted attestation with that chain."},"lastAttestationNonce(uint32)":{"notice":"Returns the nonce of the last attestation submitted by a Notary with a given agent index."},"nextAgentRoot()":{"notice":"Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over."},"passAgentRoot()":{"notice":"Attempts to pass a quarantined Agent Merkle Root to a local Light Manager."}},"version":1},"developerDoc":{"kind":"dev","methods":{"acceptAttestation(uint32,uint256,bytes,bytes32,uint128[])":{"params":{"agentRoot":"Agent Merkle Root from the Attestation","attPayload":"Raw payload with Attestation data","notaryIndex":"Index of Attestation Notary in Agent Merkle Tree","sigIndex":"Index of stored Notary signature","snapGas":"Gas data for each chain in the Attestation's snapshot"},"returns":{"wasAccepted":"     Whether the Attestation was accepted"}},"destStatus()":{"returns":{"agentRootTime":"   Timestamp when latest agent root was accepted","notaryIndex":"     Index of Notary who signed the latest agent root","snapRootTime":"    Timestamp when latest snapshot root was accepted"}},"getAttestation(uint256)":{"details":"Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit. Will return an empty signature if this contract is deployed on Synapse Chain.","params":{"index":"Attestation index"},"returns":{"attPayload":"      Raw payload with Attestation data","attSignature":"    Notary signature for the reported attestation"}},"getGasData(uint32)":{"details":"Will return empty values if there is no data for the domain, or if the notary who provided the data is in dispute.","params":{"domain":"Domain for the chain"},"returns":{"dataMaturity":"    Gas data age in seconds","gasData":"         Gas data for the chain"}},"lastAttestationNonce(uint32)":{"details":"Will return zero if the Notary hasn't submitted any attestations yet."},"passAgentRoot()":{"details":"Will do nothing, if root optimistic period is not over.","returns":{"rootPending":" Whether there is a pending agent merkle root left"}}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"notaryIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint256\",\"name\":\"sigIndex\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"attPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"agentRoot\",\"type\":\"bytes32\"},{\"internalType\":\"ChainGas[]\",\"name\":\"snapGas\",\"type\":\"uint128[]\"}],\"name\":\"acceptAttestation\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"wasAccepted\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"attestationsAmount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"destStatus\",\"outputs\":[{\"internalType\":\"uint40\",\"name\":\"snapRootTime\",\"type\":\"uint40\"},{\"internalType\":\"uint40\",\"name\":\"agentRootTime\",\"type\":\"uint40\"},{\"internalType\":\"uint32\",\"name\":\"notaryIndex\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getAttestation\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"attPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"attSignature\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"}],\"name\":\"getGasData\",\"outputs\":[{\"internalType\":\"GasData\",\"name\":\"gasData\",\"type\":\"uint96\"},{\"internalType\":\"uint256\",\"name\":\"dataMaturity\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"notaryIndex\",\"type\":\"uint32\"}],\"name\":\"lastAttestationNonce\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"nextAgentRoot\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"passAgentRoot\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"rootPending\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"acceptAttestation(uint32,uint256,bytes,bytes32,uint128[])\":{\"params\":{\"agentRoot\":\"Agent Merkle Root from the Attestation\",\"attPayload\":\"Raw payload with Attestation data\",\"notaryIndex\":\"Index of Attestation Notary in Agent Merkle Tree\",\"sigIndex\":\"Index of stored Notary signature\",\"snapGas\":\"Gas data for each chain in the Attestation's snapshot\"},\"returns\":{\"wasAccepted\":\"     Whether the Attestation was accepted\"}},\"destStatus()\":{\"returns\":{\"agentRootTime\":\"   Timestamp when latest agent root was accepted\",\"notaryIndex\":\"     Index of Notary who signed the latest agent root\",\"snapRootTime\":\"    Timestamp when latest snapshot root was accepted\"}},\"getAttestation(uint256)\":{\"details\":\"Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit. Will return an empty signature if this contract is deployed on Synapse Chain.\",\"params\":{\"index\":\"Attestation index\"},\"returns\":{\"attPayload\":\"      Raw payload with Attestation data\",\"attSignature\":\"    Notary signature for the reported attestation\"}},\"getGasData(uint32)\":{\"details\":\"Will return empty values if there is no data for the domain, or if the notary who provided the data is in dispute.\",\"params\":{\"domain\":\"Domain for the chain\"},\"returns\":{\"dataMaturity\":\"    Gas data age in seconds\",\"gasData\":\"         Gas data for the chain\"}},\"lastAttestationNonce(uint32)\":{\"details\":\"Will return zero if the Notary hasn't submitted any attestations yet.\"},\"passAgentRoot()\":{\"details\":\"Will do nothing, if root optimistic period is not over.\",\"returns\":{\"rootPending\":\" Whether there is a pending agent merkle root left\"}}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"acceptAttestation(uint32,uint256,bytes,bytes32,uint128[])\":{\"notice\":\"Accepts an attestation, which local `AgentManager` verified to have been signed by an active Notary for this chain. \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain. - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree. - Messages coming from chains included in the Attestation's snapshot could be proven. - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken. \u003e Will revert if any of these is true: \u003e - Called by anyone other than local `AgentManager`. \u003e - Attestation payload is not properly formatted. \u003e - Attestation signer is in Dispute. \u003e - Attestation's snapshot root has been previously submitted. Note: agentRoot and snapGas have been verified by the local `AgentManager`.\"},\"attestationsAmount()\":{\"notice\":\"Returns the total amount of Notaries attestations that have been accepted.\"},\"destStatus()\":{\"notice\":\"Returns status of Destination contract as far as snapshot/agent roots are concerned\"},\"getAttestation(uint256)\":{\"notice\":\"Returns a Notary-signed attestation with a given index. \u003e Index refers to the list of all attestations accepted by this contract.\"},\"getGasData(uint32)\":{\"notice\":\"Returns the gas data for a given chain from the latest accepted attestation with that chain.\"},\"lastAttestationNonce(uint32)\":{\"notice\":\"Returns the nonce of the last attestation submitted by a Notary with a given agent index.\"},\"nextAgentRoot()\":{\"notice\":\"Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\"},\"passAgentRoot()\":{\"notice\":\"Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"InterfaceDestination\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"acceptAttestation(uint32,uint256,bytes,bytes32,uint128[])":"39fe2736","attestationsAmount()":"3cf7b120","destStatus()":"40989152","getAttestation(uint256)":"29be4db2","getGasData(uint32)":"d0dd0675","lastAttestationNonce(uint32)":"305b29ee","nextAgentRoot()":"55252dd1","passAgentRoot()":"a554d1e3"}},"solidity/LightManager.sol:InterfaceLightManager":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"inputs":[],"name":"cancelProposedAgentRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"agentRoot_","type":"bytes32"}],"name":"proposeAgentRootWhenStuck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proposedAgentRootData","outputs":[{"internalType":"bytes32","name":"agentRoot_","type":"bytes32"},{"internalType":"uint256","name":"proposedAt_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"msgOrigin","type":"uint32"},{"internalType":"uint256","name":"proofMaturity","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"remoteWithdrawTips","outputs":[{"internalType":"bytes4","name":"magicValue","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"resolveProposedAgentRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"agentRoot_","type":"bytes32"}],"name":"setAgentRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"},{"components":[{"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"uint32","name":"index","type":"uint32"}],"internalType":"struct AgentStatus","name":"status","type":"tuple"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"updateAgentStatus","outputs":[],"stateMutability":"nonpayable","type":"function"}],"userDoc":{"kind":"user","methods":{"cancelProposedAgentRoot()":{"notice":"Allows contract owner to cancel the previously proposed agent root."},"proposeAgentRootWhenStuck(bytes32)":{"notice":"Allows contract owner to set the agent root to resolve the \"stuck\" chain by proposing the new agent root. The contract owner will be able to resolve the proposed agent root after a certain period of time. Note: this function could be called multiple times, each time the timer will be reset. This could only be called if no fresh data has been submitted by the Notaries to the Inbox, indicating that the chain is stuck for one of the reasons: - All active Notaries are in Dispute. - No active Notaries exist under the current agent root."},"proposedAgentRootData()":{"notice":"Returns the latest proposed agent root and the timestamp when it was proposed."},"remoteWithdrawTips(uint32,uint256,address,uint256)":{"notice":"Withdraws locked base message tips from local Origin to the recipient."},"resolveProposedAgentRoot()":{"notice":"Allows contract owner to resolve the previously proposed agent root. This will update the agent root, allowing the agents to update their status, effectively resolving the \"stuck\" chain."},"setAgentRoot(bytes32)":{"notice":"Updates the root of Agent Merkle Tree that the Light Manager is tracking. Could be only called by a local Destination contract, which is supposed to verify the attested Agent Merkle Roots."},"updateAgentStatus(address,(uint8,uint32,uint32),bytes32[])":{"notice":"Updates agent status, using a proof against the latest known Agent Merkle Root."}},"version":1},"developerDoc":{"kind":"dev","methods":{"cancelProposedAgentRoot()":{"details":"Will revert if any of the following conditions is met: - Caller is not the contract owner. - No agent root was proposed."},"proposeAgentRootWhenStuck(bytes32)":{"details":"Will revert if any of the following conditions is met: - Caller is not the contract owner. - Agent root is empty. - The chain is not in a stuck state (has recently received a fresh data from the Notaries).","params":{"agentRoot_":"New Agent Merkle Root that is proposed to be set"}},"proposedAgentRootData()":{"details":"Will return zero values if no agent root was proposed, or if the proposed agent root was already resolved."},"remoteWithdrawTips(uint32,uint256,address,uint256)":{"details":"Could only be remote-called by BondingManager contract on Synapse Chain. Note: as an extra security check this function returns its own selector, so that Destination could verify that a \"remote\" function was called when executing a manager message.","params":{"amount":"Tips value to withdraw","recipient":"Address to withdraw tips to"}},"resolveProposedAgentRoot()":{"details":"Will revert if any of the following conditions is met: - Caller is not the contract owner. - No agent root was proposed. - Not enough time has passed since the agent root was proposed."},"setAgentRoot(bytes32)":{"params":{"agentRoot_":"New Agent Merkle Root"}},"updateAgentStatus(address,(uint8,uint32,uint32),bytes32[])":{"details":"Will revert if the provided proof doesn't match the latest merkle root.","params":{"agent":"Agent address","proof":"Merkle proof of Active status for the agent","status":"Structure specifying agent status: (flag, domain, index)"}}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"cancelProposedAgentRoot\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"agentRoot_\",\"type\":\"bytes32\"}],\"name\":\"proposeAgentRootWhenStuck\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"proposedAgentRootData\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"agentRoot_\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"proposedAt_\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"msgOrigin\",\"type\":\"uint32\"},{\"internalType\":\"uint256\",\"name\":\"proofMaturity\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"remoteWithdrawTips\",\"outputs\":[{\"internalType\":\"bytes4\",\"name\":\"magicValue\",\"type\":\"bytes4\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"resolveProposedAgentRoot\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"agentRoot_\",\"type\":\"bytes32\"}],\"name\":\"setAgentRoot\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"index\",\"type\":\"uint32\"}],\"internalType\":\"struct AgentStatus\",\"name\":\"status\",\"type\":\"tuple\"},{\"internalType\":\"bytes32[]\",\"name\":\"proof\",\"type\":\"bytes32[]\"}],\"name\":\"updateAgentStatus\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"cancelProposedAgentRoot()\":{\"details\":\"Will revert if any of the following conditions is met: - Caller is not the contract owner. - No agent root was proposed.\"},\"proposeAgentRootWhenStuck(bytes32)\":{\"details\":\"Will revert if any of the following conditions is met: - Caller is not the contract owner. - Agent root is empty. - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\",\"params\":{\"agentRoot_\":\"New Agent Merkle Root that is proposed to be set\"}},\"proposedAgentRootData()\":{\"details\":\"Will return zero values if no agent root was proposed, or if the proposed agent root was already resolved.\"},\"remoteWithdrawTips(uint32,uint256,address,uint256)\":{\"details\":\"Could only be remote-called by BondingManager contract on Synapse Chain. Note: as an extra security check this function returns its own selector, so that Destination could verify that a \\\"remote\\\" function was called when executing a manager message.\",\"params\":{\"amount\":\"Tips value to withdraw\",\"recipient\":\"Address to withdraw tips to\"}},\"resolveProposedAgentRoot()\":{\"details\":\"Will revert if any of the following conditions is met: - Caller is not the contract owner. - No agent root was proposed. - Not enough time has passed since the agent root was proposed.\"},\"setAgentRoot(bytes32)\":{\"params\":{\"agentRoot_\":\"New Agent Merkle Root\"}},\"updateAgentStatus(address,(uint8,uint32,uint32),bytes32[])\":{\"details\":\"Will revert if the provided proof doesn't match the latest merkle root.\",\"params\":{\"agent\":\"Agent address\",\"proof\":\"Merkle proof of Active status for the agent\",\"status\":\"Structure specifying agent status: (flag, domain, index)\"}}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"cancelProposedAgentRoot()\":{\"notice\":\"Allows contract owner to cancel the previously proposed agent root.\"},\"proposeAgentRootWhenStuck(bytes32)\":{\"notice\":\"Allows contract owner to set the agent root to resolve the \\\"stuck\\\" chain by proposing the new agent root. The contract owner will be able to resolve the proposed agent root after a certain period of time. Note: this function could be called multiple times, each time the timer will be reset. This could only be called if no fresh data has been submitted by the Notaries to the Inbox, indicating that the chain is stuck for one of the reasons: - All active Notaries are in Dispute. - No active Notaries exist under the current agent root.\"},\"proposedAgentRootData()\":{\"notice\":\"Returns the latest proposed agent root and the timestamp when it was proposed.\"},\"remoteWithdrawTips(uint32,uint256,address,uint256)\":{\"notice\":\"Withdraws locked base message tips from local Origin to the recipient.\"},\"resolveProposedAgentRoot()\":{\"notice\":\"Allows contract owner to resolve the previously proposed agent root. This will update the agent root, allowing the agents to update their status, effectively resolving the \\\"stuck\\\" chain.\"},\"setAgentRoot(bytes32)\":{\"notice\":\"Updates the root of Agent Merkle Tree that the Light Manager is tracking. Could be only called by a local Destination contract, which is supposed to verify the attested Agent Merkle Roots.\"},\"updateAgentStatus(address,(uint8,uint32,uint32),bytes32[])\":{\"notice\":\"Updates agent status, using a proof against the latest known Agent Merkle Root.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"InterfaceLightManager\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"cancelProposedAgentRoot()":"91ea3c34","proposeAgentRootWhenStuck(bytes32)":"dbad9562","proposedAgentRootData()":"5396feef","remoteWithdrawTips(uint32,uint256,address,uint256)":"1fa07138","resolveProposedAgentRoot()":"38416281","setAgentRoot(bytes32)":"58668176","updateAgentStatus(address,(uint8,uint32,uint32),bytes32[])":"cbd05965"}},"solidity/LightManager.sol:InterfaceOrigin":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"inputs":[{"internalType":"uint32","name":"destination","type":"uint32"},{"internalType":"uint256","name":"paddedRequest","type":"uint256"},{"internalType":"uint256","name":"contentLength","type":"uint256"}],"name":"getMinimumTipsValue","outputs":[{"internalType":"uint256","name":"tipsValue","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"destination","type":"uint32"},{"internalType":"bytes32","name":"recipient","type":"bytes32"},{"internalType":"uint32","name":"optimisticPeriod","type":"uint32"},{"internalType":"uint256","name":"paddedRequest","type":"uint256"},{"internalType":"bytes","name":"content","type":"bytes"}],"name":"sendBaseMessage","outputs":[{"internalType":"uint32","name":"messageNonce","type":"uint32"},{"internalType":"bytes32","name":"messageHash","type":"bytes32"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint32","name":"destination","type":"uint32"},{"internalType":"uint32","name":"optimisticPeriod","type":"uint32"},{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"sendManagerMessage","outputs":[{"internalType":"uint32","name":"messageNonce","type":"uint32"},{"internalType":"bytes32","name":"messageHash","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawTips","outputs":[],"stateMutability":"nonpayable","type":"function"}],"userDoc":{"kind":"user","methods":{"getMinimumTipsValue(uint32,uint256,uint256)":{"notice":"Returns the minimum tips value for sending a message to a given destination."},"sendBaseMessage(uint32,bytes32,uint32,uint256,bytes)":{"notice":"Send a message to the recipient located on destination domain."},"sendManagerMessage(uint32,uint32,bytes)":{"notice":"Send a manager message to the destination domain."},"withdrawTips(address,uint256)":{"notice":"Withdraws locked base message tips to the recipient."}},"version":1},"developerDoc":{"kind":"dev","methods":{"getMinimumTipsValue(uint32,uint256,uint256)":{"details":"Using at least `tipsValue` as `msg.value` for `sendBaseMessage()` will guarantee that the message will be accepted.","params":{"contentLength":"The length of the message content","destination":"Domain of destination chain","paddedRequest":"Padded encoded message execution request on destination chain"},"returns":{"tipsValue":"       Minimum tips value for a message to be accepted"}},"sendBaseMessage(uint32,bytes32,uint32,uint256,bytes)":{"details":"Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered. Will revert if any of these is true: - `destination` is equal to contract's local domain - `content` length is greater than `MAX_CONTENT_BYTES` - `msg.value` is lower than value of minimum tips for the given message","params":{"content":"Raw bytes content of message","destination":"Domain of destination chain","optimisticPeriod":"Optimistic period for message execution on destination chain","paddedRequest":"Padded encoded message execution request on destination chain","recipient":"Address of recipient on destination chain as bytes32"},"returns":{"messageHash":"         Hash of the sent message","messageNonce":"        Nonce of the sent message"}},"sendManagerMessage(uint32,uint32,bytes)":{"details":"This could only be called by AgentManager, which takes care of encoding the calldata payload. Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain so that the AgentManager could verify where the Manager Message came from and how mature is the proof. Note: function is not payable, as no tips are required for sending a manager message. Will revert if `destination` is equal to contract's local domain.","params":{"destination":"Domain of destination chain","optimisticPeriod":"Optimistic period for message execution on destination chain","payload":"Payload for calling AgentManager on destination chain (with extra security args)"}},"withdrawTips(address,uint256)":{"details":"Could only be called by a local AgentManager.","params":{"amount":"Tips value to withdraw","recipient":"Address to withdraw tips to"}}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"destination\",\"type\":\"uint32\"},{\"internalType\":\"uint256\",\"name\":\"paddedRequest\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"contentLength\",\"type\":\"uint256\"}],\"name\":\"getMinimumTipsValue\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"tipsValue\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"destination\",\"type\":\"uint32\"},{\"internalType\":\"bytes32\",\"name\":\"recipient\",\"type\":\"bytes32\"},{\"internalType\":\"uint32\",\"name\":\"optimisticPeriod\",\"type\":\"uint32\"},{\"internalType\":\"uint256\",\"name\":\"paddedRequest\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"content\",\"type\":\"bytes\"}],\"name\":\"sendBaseMessage\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"messageNonce\",\"type\":\"uint32\"},{\"internalType\":\"bytes32\",\"name\":\"messageHash\",\"type\":\"bytes32\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"destination\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"optimisticPeriod\",\"type\":\"uint32\"},{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"sendManagerMessage\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"messageNonce\",\"type\":\"uint32\"},{\"internalType\":\"bytes32\",\"name\":\"messageHash\",\"type\":\"bytes32\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"withdrawTips\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"getMinimumTipsValue(uint32,uint256,uint256)\":{\"details\":\"Using at least `tipsValue` as `msg.value` for `sendBaseMessage()` will guarantee that the message will be accepted.\",\"params\":{\"contentLength\":\"The length of the message content\",\"destination\":\"Domain of destination chain\",\"paddedRequest\":\"Padded encoded message execution request on destination chain\"},\"returns\":{\"tipsValue\":\"       Minimum tips value for a message to be accepted\"}},\"sendBaseMessage(uint32,bytes32,uint32,uint256,bytes)\":{\"details\":\"Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered. Will revert if any of these is true: - `destination` is equal to contract's local domain - `content` length is greater than `MAX_CONTENT_BYTES` - `msg.value` is lower than value of minimum tips for the given message\",\"params\":{\"content\":\"Raw bytes content of message\",\"destination\":\"Domain of destination chain\",\"optimisticPeriod\":\"Optimistic period for message execution on destination chain\",\"paddedRequest\":\"Padded encoded message execution request on destination chain\",\"recipient\":\"Address of recipient on destination chain as bytes32\"},\"returns\":{\"messageHash\":\"         Hash of the sent message\",\"messageNonce\":\"        Nonce of the sent message\"}},\"sendManagerMessage(uint32,uint32,bytes)\":{\"details\":\"This could only be called by AgentManager, which takes care of encoding the calldata payload. Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain so that the AgentManager could verify where the Manager Message came from and how mature is the proof. Note: function is not payable, as no tips are required for sending a manager message. Will revert if `destination` is equal to contract's local domain.\",\"params\":{\"destination\":\"Domain of destination chain\",\"optimisticPeriod\":\"Optimistic period for message execution on destination chain\",\"payload\":\"Payload for calling AgentManager on destination chain (with extra security args)\"}},\"withdrawTips(address,uint256)\":{\"details\":\"Could only be called by a local AgentManager.\",\"params\":{\"amount\":\"Tips value to withdraw\",\"recipient\":\"Address to withdraw tips to\"}}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"getMinimumTipsValue(uint32,uint256,uint256)\":{\"notice\":\"Returns the minimum tips value for sending a message to a given destination.\"},\"sendBaseMessage(uint32,bytes32,uint32,uint256,bytes)\":{\"notice\":\"Send a message to the recipient located on destination domain.\"},\"sendManagerMessage(uint32,uint32,bytes)\":{\"notice\":\"Send a manager message to the destination domain.\"},\"withdrawTips(address,uint256)\":{\"notice\":\"Withdraws locked base message tips to the recipient.\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"InterfaceOrigin\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"getMinimumTipsValue(uint32,uint256,uint256)":"4fc6ad85","sendBaseMessage(uint32,bytes32,uint32,uint256,bytes)":"873661bd","sendManagerMessage(uint32,uint32,bytes)":"a1c702a7","withdrawTips(address,uint256)":"4e04e7a7"}},"solidity/LightManager.sol:LightManager":{"code":"0x6101006040523480156200001257600080fd5b50604051620030e0380380620030e0833981016040819052620000359162000148565b60408051808201909152600580825264302e302e3360d81b60208301526080528181620000628162000177565b60a08181525050506200007f620000bd60201b620018ee1760201c565b63ffffffff90811660c081905291811660e052831690039050620000b65760405163079597d560e51b815260040160405180910390fd5b506200019f565b6000620000d546620000da60201b620018fe1760201c565b905090565b600063ffffffff821115620001445760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201526532206269747360d01b606482015260840160405180910390fd5b5090565b6000602082840312156200015b57600080fd5b815163ffffffff811681146200017057600080fd5b9392505050565b8051602080830151919081101562000199576000198160200360031b1b821691505b50919050565b60805160a05160c05160e051612ef9620001e76000396000818161036b015281816105150152612301015260006103af015260006102fb015260006102d80152612ef96000f3fe608060405234801561001057600080fd5b50600436106101c45760003560e01c806379ba5097116100f9578063c0c53b8b11610097578063e30c397811610071578063e30c397814610470578063e3a96cbd14610481578063f2fde38b146104a6578063fb0e722b146104b957600080fd5b8063c0c53b8b14610437578063cbd059651461044a578063dbad95621461045d57600080fd5b806391ea3c34116100d357806391ea3c34146103f6578063938b5f32146103fe578063a2155c3414610411578063b269681d1461042457600080fd5b806379ba5097146103a25780638d3638f4146103aa5780638da5cb5b146103d157600080fd5b80633aaeccc6116101665780635866817611610140578063586681761461032b57806360fc84661461033e578063715018a61461035e578063717b86381461036657600080fd5b80633aaeccc6146102aa5780635396feef146102b257806354fd4d50146102cd57600080fd5b80632de5aaf7116101a25780632de5aaf7146102475780633463d1b11461026857806336cba43c1461028b57806338416281146102a257600080fd5b80631fa07138146101c95780632853a0e61461021257806328f3fac914610227575b600080fd5b6101dc6101d7366004612579565b6104cc565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020015b60405180910390f35b6102256102203660046125bf565b610660565b005b61023a610235366004612604565b6106b4565b604051610209919061268e565b61025a61025536600461269c565b610756565b6040516102099291906126b5565b61027b610276366004612604565b6107a3565b60405161020994939291906126d2565b61029460fb5481565b604051908152602001610209565b61022561091e565b60cd54610294565b60fc5460fd5460408051928352602083019190915201610209565b6040805180820182527f000000000000000000000000000000000000000000000000000000000000000081527f0000000000000000000000000000000000000000000000000000000000000000602082015290516102099190612777565b61022561033936600461269c565b6109f7565b61035161034c36600461278a565b610a47565b60405161020991906127ff565b610225610bb2565b61038d7f000000000000000000000000000000000000000000000000000000000000000081565b60405163ffffffff9091168152602001610209565b610225610bbc565b61038d7f000000000000000000000000000000000000000000000000000000000000000081565b6033546001600160a01b03165b6040516001600160a01b039091168152602001610209565b610225610c66565b60c9546103de906001600160a01b031681565b61022561041f366004612893565b610ce6565b60ca546103de906001600160a01b031681565b6102256104453660046128cc565b6110d0565b610225610458366004612a11565b611270565b61022561046b36600461269c565b61151d565b6065546001600160a01b03166103de565b61049461048f36600461269c565b611679565b60405161020996959493929190612ad7565b6102256104b4366004612604565b611865565b60cb546103de906001600160a01b031681565b60ca546000906001600160a01b03163314610513576040517f6efcc49f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000063ffffffff168563ffffffff1614610578576040517f2b3a807f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b620151808410156105b5576040517fdf5728f300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60c9546040517f4e04e7a70000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301526024820185905290911690634e04e7a790604401600060405180830381600087803b15801561061c57600080fd5b505af1158015610630573d6000803e3d6000fd5b507f1fa071380000000000000000000000000000000000000000000000000000000093505050505b949350505050565b60cb546001600160a01b031633146106a4576040517fdbc2fa8500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6106af838383611998565b505050565b60408051606081018252600080825260208201819052918101919091526106da82611a59565b9050600260cc6000610702856001600160a01b03166000908152610100602052604090205490565b815260208101919091526040016000205460ff1660028111156107275761072761261f565b14801561074757506005815160058111156107445761074461261f565b14155b1561075157600481525b919050565b60408051606081018252600080825260208201819052918101829052600083815260ff60205260409020546001600160a01b03169150811561079e5761079b826106b4565b90505b915091565b60008060008060006107cb866001600160a01b03166000908152610100602052604090205490565b600081815260cc602052604080822081516060810190925280549394509192909190829060ff1660028111156108035761080361261f565b60028111156108145761081461261f565b8152905461010081046affffffffffffffffffffff9081166020808501919091526c010000000000000000000000009092046001600160a01b0316604093840152835192840151918401519299509096501693509050821561091557600060cd61087f600186612b61565b8154811061088f5761088f612b74565b600091825260209182902060408051606081018252929091015463ffffffff808216808552640100000000830482169585019590955268010000000000000000909104169082015291506109119084146108ea5781516108f0565b81602001515b63ffffffff16600090815260ff60205260409020546001600160a01b031690565b9550505b50509193509193565b610926611af5565b60fc546000819003610964576040517ff07e7d8b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60fd546109749061a8c090612ba3565b4210156109ad576040517f3fa3deaa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6109b681611b69565b600060fc81905560fd556040518181527fa2ec8d9db1d036a8700a09e8e0e537805f87edd54181a1fc08a71db281744b4e906020015b60405180910390a150565b60ca546001600160a01b03163314610a3b576040517f6efcc49f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a4481611b69565b50565b6060818067ffffffffffffffff811115610a6357610a636128ea565b604051908082528060200260200182016040528015610aa957816020015b604080518082019091526000815260606020820152815260200190600190039081610a815790505b5091503660005b82811015610ba957858582818110610aca57610aca612b74565b9050602002810190610adc9190612bb6565b91506000848281518110610af257610af2612b74565b60200260200101519050306001600160a01b0316838060200190610b169190612bf4565b604051610b24929190612c60565b600060405180830381855af49150503d8060008114610b5f576040519150601f19603f3d011682016040523d82523d6000602084013e610b64565b606091505b5060208301521515808252833517610ba0577f4d6a23280000000000000000000000000000000000000000000000000000000060005260046000fd5b50600101610ab0565b50505092915050565b610bba611af5565b565b60655433906001600160a01b03168114610c5d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f74207468652060448201527f6e6577206f776e6572000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b610a4481611ba7565b610c6e611af5565b60fc546000819003610cac576040517ff07e7d8b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600060fc81905560fd556040518181527fc9b788a7a7ebe95a0a3f82c9850959f0cc1657d1fb19a05ad1cf60877651725f906020016109ec565b60cb546001600160a01b03163314610d2a576040517fdbc2fa8500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b63ffffffff8216600090815260cc602052604081205460ff166002811115610d5457610d5461261f565b14610d8b576040517fd9d49b4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b63ffffffff8116600090815260cc602052604081205460ff166002811115610db557610db561261f565b14610dec576040517f6893014300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604080516060808201835263ffffffff808616835284811660208401908152600084860181815260cd8054600181810183559382905296517f83978b4c69c48dd978ab43fe30f077615294f938fb7f936d9eb340e51ea7db2e909701805494519251861668010000000000000000027fffffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffff938716640100000000027fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000090961698909616979097179390931716929092179093559154835191820190935290819081526affffffffffffffffffffff83166020808301919091526000604092830181905263ffffffff8716815260cc909152208151815482907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001836002811115610f3957610f3961261f565b0217905550602082015181546040938401516001600160a01b03166c01000000000000000000000000026bffffffffffffffffffffffff6affffffffffffffffffffff909316610100029290921660ff9091161717905580516060810190915280600181526affffffffffffffffffffff83166020808301919091526000604092830181905263ffffffff8616815260cc909152208151815482907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600183600281111561100a5761100a61261f565b0217905550602082015181546040909301516001600160a01b03166c01000000000000000000000000026bffffffffffffffffffffffff6affffffffffffffffffffff909216610100029190911660ff909316929092179190911790557fd0672fae056abe2bf0637742527d49add67fdb68192a6c6f6bf86eac19fe0530611093600183612c70565b604080516affffffffffffffffffffff909216825263ffffffff808716602084015285169082015260600160405180910390a16106af8383611bd8565b600054610100900460ff16158080156110f05750600054600160ff909116105b8061110a5750303b15801561110a575060005460ff166001145b611196576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152608401610c54565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905580156111f457600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b6111ff848484611c59565b611207611d47565b801561126a57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50505050565b60408083015163ffffffff16600090815260ff60205220546001600160a01b031680158015906112b25750836001600160a01b0316816001600160a01b031614155b156112e9576040517f4ae22ee400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006112fe8460000151856020015187611de6565b9050600060fb5490508061131f866040015163ffffffff1684876020611e1d565b14611356576040517f4cc472e700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0383166113c9576040858101805163ffffffff908116600090815260ff602090815284822080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b038d169081179091559351938252610100905292909220911690555b600081815260fe602090815260408083206001600160a01b038a1684529091529020855181548792919082907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600183600581111561142b5761142b61261f565b021790555060208281015182546040948501517fffffffffffffffffffffffffffffffffffffffffffffff0000000000000000ff90911661010063ffffffff938416027fffffffffffffffffffffffffffffffffffffffffffffff00000000ffffffffff1617650100000000009183169190910217909255870151875192516001600160a01b038a169391909216917f8f9b8b0f4f062833bec85ea9a8465e4a1207b4be6eb565bbd0ae8b913588d04e916114e591612c9b565b60405180910390a36005855160058111156115025761150261261f565b0361151557611515856040015133611ec5565b505050505050565b611525611af5565b60ca54604080517f4098915200000000000000000000000000000000000000000000000000000000815290516000926001600160a01b03169163409891529160048083019260609291908290030181865afa158015611588573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ac9190612cbe565b505090508064ffffffffff166138406115c59190612ba3565b4210156115fe576040517f5be16c4600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000829003611639576040517f87c758ba00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60fc8290554260fd556040518281527fc222e0af9f2301ee0bfafe1044550b0553f5bdc4a65cb92cc2568820b5bf29449060200160405180910390a15050565b60008060008060608060cd8054905087106116c0576040517f1390f2a100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600060cd88815481106116d5576116d5612b74565b6000918252602080832060408051606081018252939091015463ffffffff8082168086526401000000008304821686860190815268010000000000000000909304821686850152865260ff9093528185205490519092168452909220546001600160a01b03928316995090925016604082015190965063ffffffff16156117ae5760408082015163ffffffff16600090815260ff60205220546001600160a01b031660408281015163ffffffff16600090815260cc60205220549095506c0100000000000000000000000090046001600160a01b031693505b60cb546040517fc495912b000000000000000000000000000000000000000000000000000000008152600481018a90526001600160a01b039091169063c495912b90602401600060405180830381865afa158015611810573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526118569190810190612d87565b97999698509496939592505050565b61186d611af5565b606580546001600160a01b0383167fffffffffffffffffffffffff000000000000000000000000000000000000000090911681179091556118b66033546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b60006118f9466118fe565b905090565b600063ffffffff821115611994576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201527f32206269747300000000000000000000000000000000000000000000000000006064820152608401610c54565b5090565b60006119a383611a59565b90506119ae816121d6565b8363ffffffff16816020015163ffffffff16146119f7576040517f1612d2ee00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b826001600160a01b03168463ffffffff167f8f9b8b0f4f062833bec85ea9a8465e4a1207b4be6eb565bbd0ae8b913588d04e6004604051611a389190612c9b565b60405180910390a3611a4e816040015183611ec5565b61126a848484612243565b60408051606080820183526000808352602080840182905283850182905260fb54825260fe81528482206001600160a01b038716835290528390208351918201909352825491929091829060ff166005811115611ab857611ab861261f565b6005811115611ac957611ac961261f565b8152905463ffffffff610100820481166020840152650100000000009091041660409091015292915050565b6033546001600160a01b03163314610bba576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610c54565b8060fb5414610a445760fb8190556040518181527f2cbc14f49c068133583f7cb530018af451c87c1cf1327cf2a4ff4698c4730aa4906020016109ec565b606580547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055610a4481612378565b60ca546040517fa2155c3400000000000000000000000000000000000000000000000000000000815263ffffffff8085166004830152831660248201526001600160a01b039091169063a2155c34906044015b600060405180830381600087803b158015611c4557600080fd5b505af1158015611515573d6000803e3d6000fd5b600054610100900460ff16611cf0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610c54565b60c980546001600160a01b039485167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161790915560ca80549385169382169390931790925560cb8054919093169116179055565b600054610100900460ff16611dde576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610c54565b610bba6123e2565b6000838383604051602001611dfd93929190612deb565b6040516020818303038152906040528051906020012090505b9392505050565b815160009082811115611e5c576040517fc5360feb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b84915060005b81811015611e9957611e8f83868381518110611e8057611e80612b74565b60200260200101518984612482565b9250600101611e62565b50805b83811015611ebb57611eb18360008984612482565b9250600101611e9c565b5050949350505050565b63ffffffff8216600090815260cc60205260408082208151606081019092528054829060ff166002811115611efc57611efc61261f565b6002811115611f0d57611f0d61261f565b8152905461010081046affffffffffffffffffffff1660208301526c0100000000000000000000000090046001600160a01b03166040909101529050600281516002811115611f5e57611f5e61261f565b03611f95576040517ff10068b500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60028082526001600160a01b03831660408084019190915263ffffffff8516600090815260cc6020522082518154849383917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016906001908490811115611ffe57611ffe61261f565b021790555060208281015182546040909401516001600160a01b03166c01000000000000000000000000026bffffffffffffffffffffffff6affffffffffffffffffffff928316610100021660ff909516949094179390931790915582015160009116156121cc576000600183602001516120799190612c70565b6affffffffffffffffffffff169050600060cd828154811061209d5761209d612b74565b600091825260209182902060408051606081018252919092015463ffffffff808216835264010000000082048116948301949094526801000000000000000090049092169082015260cd80549192508791849081106120fe576120fe612b74565b60009182526020918290200180547fffffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffff166801000000000000000063ffffffff9485160217905582015187821691161461215b57806020015161215e565b80515b63ffffffff818116600081815260cc60209081526040808320929092558151878152938b16908401528201526001600160a01b03871660608201529093507fb4cad5624e1d1c6c622ec70516ee582fe3f6519440c5b47e5165141edc9c54cf9060800160405180910390a150505b61126a84826124ab565b6001815160058111156121eb576121eb61261f565b1415801561220c57506002815160058111156122095761220961261f565b14155b15610a44576040517fec3d0d8500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60c9546040805163ffffffff861660248201526001600160a01b03858116604483015284811660648084019190915283518084039091018152608490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f9d228a510000000000000000000000000000000000000000000000000000000017905291517fa1c702a7000000000000000000000000000000000000000000000000000000008152919092169163a1c702a79161232f917f000000000000000000000000000000000000000000000000000000000000000091620151809190600401612e63565b60408051808303816000875af115801561234d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123719190612e95565b5050505050565b603380546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff16612479576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610c54565b610bba33611ba7565b6000600183831c1681036124a15761249a8585612502565b9050610658565b61249a8486612502565b60ca546040517f6116921800000000000000000000000000000000000000000000000000000000815263ffffffff8085166004830152831660248201526001600160a01b0390911690636116921890604401611c2b565b600082158015612510575081155b1561251d5750600061254a565b60408051602081018590529081018390526060016040516020818303038152906040528051906020012090505b92915050565b63ffffffff81168114610a4457600080fd5b80356001600160a01b038116811461075157600080fd5b6000806000806080858703121561258f57600080fd5b843561259a81612550565b9350602085013592506125af60408601612562565b9396929550929360600135925050565b6000806000606084860312156125d457600080fd5b83356125df81612550565b92506125ed60208501612562565b91506125fb60408501612562565b90509250925092565b60006020828403121561261657600080fd5b611e1682612562565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6006811061265e5761265e61261f565b9052565b61266d82825161264e565b60208181015163ffffffff9081169184019190915260409182015116910152565b6060810161254a8284612662565b6000602082840312156126ae57600080fd5b5035919050565b6001600160a01b038316815260808101611e166020830184612662565b60808101600386106126e6576126e661261f565b9481526001600160a01b0393841660208201529190921660408201526060015290565b60005b8381101561272457818101518382015260200161270c565b50506000910152565b60008151808452612745816020860160208601612709565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b602081526000611e16602083018461272d565b6000806020838503121561279d57600080fd5b823567ffffffffffffffff808211156127b557600080fd5b818501915085601f8301126127c957600080fd5b8135818111156127d857600080fd5b8660208260051b85010111156127ed57600080fd5b60209290920196919550909350505050565b60006020808301818452808551808352604092508286019150828160051b87010184880160005b83811015612885578883037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc001855281518051151584528701518784018790526128728785018261272d565b9588019593505090860190600101612826565b509098975050505050505050565b600080604083850312156128a657600080fd5b82356128b181612550565b915060208301356128c181612550565b809150509250929050565b6000806000606084860312156128e157600080fd5b6125df84612562565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040516060810167ffffffffffffffff8111828210171561293c5761293c6128ea565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715612989576129896128ea565b604052919050565b600082601f8301126129a257600080fd5b8135602067ffffffffffffffff8211156129be576129be6128ea565b8160051b6129cd828201612942565b92835284810182019282810190878511156129e757600080fd5b83870192505b84831015612a06578235825291830191908301906129ed565b979650505050505050565b600080600083850360a0811215612a2757600080fd5b612a3085612562565b935060607fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe082011215612a6257600080fd5b50612a6b612919565b602085013560068110612a7d57600080fd5b81526040850135612a8d81612550565b60208201526060850135612aa081612550565b60408201529150608084013567ffffffffffffffff811115612ac157600080fd5b612acd86828701612991565b9150509250925092565b60006001600160a01b0380891683528088166020840152808716604084015280861660608401525060c06080830152612b1360c083018561272d565b82810360a0840152612b25818561272d565b9998505050505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561254a5761254a612b32565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b8082018082111561254a5761254a612b32565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc1833603018112612bea57600080fd5b9190910192915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112612c2957600080fd5b83018035915067ffffffffffffffff821115612c4457600080fd5b602001915036819003821315612c5957600080fd5b9250929050565b8183823760009101908152919050565b6affffffffffffffffffffff828116828216039080821115612c9457612c94612b32565b5092915050565b6020810161254a828461264e565b805164ffffffffff8116811461075157600080fd5b600080600060608486031215612cd357600080fd5b612cdc84612ca9565b9250612cea60208501612ca9565b91506040840151612cfa81612550565b809150509250925092565b600082601f830112612d1657600080fd5b815167ffffffffffffffff811115612d3057612d306128ea565b612d6160207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601612942565b818152846020838601011115612d7657600080fd5b610658826020830160208701612709565b60008060408385031215612d9a57600080fd5b825167ffffffffffffffff80821115612db257600080fd5b612dbe86838701612d05565b93506020850151915080821115612dd457600080fd5b50612de185828601612d05565b9150509250929050565b600060068510612dfd57612dfd61261f565b5060f89390931b835260e09190911b7fffffffff0000000000000000000000000000000000000000000000000000000016600183015260601b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016600582015260190190565b600063ffffffff808616835280851660208401525060606040830152612e8c606083018461272d565b95945050505050565b60008060408385031215612ea857600080fd5b8251612eb381612550565b602093909301519294929350505056fea26469706673582212202cd7f64fbed7d2d5a15ae202ffa21ddd5e1608220a88cade750cad4af8a8be4a64736f6c63430008110033","runtime-code":"0x608060405234801561001057600080fd5b50600436106101c45760003560e01c806379ba5097116100f9578063c0c53b8b11610097578063e30c397811610071578063e30c397814610470578063e3a96cbd14610481578063f2fde38b146104a6578063fb0e722b146104b957600080fd5b8063c0c53b8b14610437578063cbd059651461044a578063dbad95621461045d57600080fd5b806391ea3c34116100d357806391ea3c34146103f6578063938b5f32146103fe578063a2155c3414610411578063b269681d1461042457600080fd5b806379ba5097146103a25780638d3638f4146103aa5780638da5cb5b146103d157600080fd5b80633aaeccc6116101665780635866817611610140578063586681761461032b57806360fc84661461033e578063715018a61461035e578063717b86381461036657600080fd5b80633aaeccc6146102aa5780635396feef146102b257806354fd4d50146102cd57600080fd5b80632de5aaf7116101a25780632de5aaf7146102475780633463d1b11461026857806336cba43c1461028b57806338416281146102a257600080fd5b80631fa07138146101c95780632853a0e61461021257806328f3fac914610227575b600080fd5b6101dc6101d7366004612579565b6104cc565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020015b60405180910390f35b6102256102203660046125bf565b610660565b005b61023a610235366004612604565b6106b4565b604051610209919061268e565b61025a61025536600461269c565b610756565b6040516102099291906126b5565b61027b610276366004612604565b6107a3565b60405161020994939291906126d2565b61029460fb5481565b604051908152602001610209565b61022561091e565b60cd54610294565b60fc5460fd5460408051928352602083019190915201610209565b6040805180820182527f000000000000000000000000000000000000000000000000000000000000000081527f0000000000000000000000000000000000000000000000000000000000000000602082015290516102099190612777565b61022561033936600461269c565b6109f7565b61035161034c36600461278a565b610a47565b60405161020991906127ff565b610225610bb2565b61038d7f000000000000000000000000000000000000000000000000000000000000000081565b60405163ffffffff9091168152602001610209565b610225610bbc565b61038d7f000000000000000000000000000000000000000000000000000000000000000081565b6033546001600160a01b03165b6040516001600160a01b039091168152602001610209565b610225610c66565b60c9546103de906001600160a01b031681565b61022561041f366004612893565b610ce6565b60ca546103de906001600160a01b031681565b6102256104453660046128cc565b6110d0565b610225610458366004612a11565b611270565b61022561046b36600461269c565b61151d565b6065546001600160a01b03166103de565b61049461048f36600461269c565b611679565b60405161020996959493929190612ad7565b6102256104b4366004612604565b611865565b60cb546103de906001600160a01b031681565b60ca546000906001600160a01b03163314610513576040517f6efcc49f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000063ffffffff168563ffffffff1614610578576040517f2b3a807f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b620151808410156105b5576040517fdf5728f300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60c9546040517f4e04e7a70000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301526024820185905290911690634e04e7a790604401600060405180830381600087803b15801561061c57600080fd5b505af1158015610630573d6000803e3d6000fd5b507f1fa071380000000000000000000000000000000000000000000000000000000093505050505b949350505050565b60cb546001600160a01b031633146106a4576040517fdbc2fa8500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6106af838383611998565b505050565b60408051606081018252600080825260208201819052918101919091526106da82611a59565b9050600260cc6000610702856001600160a01b03166000908152610100602052604090205490565b815260208101919091526040016000205460ff1660028111156107275761072761261f565b14801561074757506005815160058111156107445761074461261f565b14155b1561075157600481525b919050565b60408051606081018252600080825260208201819052918101829052600083815260ff60205260409020546001600160a01b03169150811561079e5761079b826106b4565b90505b915091565b60008060008060006107cb866001600160a01b03166000908152610100602052604090205490565b600081815260cc602052604080822081516060810190925280549394509192909190829060ff1660028111156108035761080361261f565b60028111156108145761081461261f565b8152905461010081046affffffffffffffffffffff9081166020808501919091526c010000000000000000000000009092046001600160a01b0316604093840152835192840151918401519299509096501693509050821561091557600060cd61087f600186612b61565b8154811061088f5761088f612b74565b600091825260209182902060408051606081018252929091015463ffffffff808216808552640100000000830482169585019590955268010000000000000000909104169082015291506109119084146108ea5781516108f0565b81602001515b63ffffffff16600090815260ff60205260409020546001600160a01b031690565b9550505b50509193509193565b610926611af5565b60fc546000819003610964576040517ff07e7d8b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60fd546109749061a8c090612ba3565b4210156109ad576040517f3fa3deaa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6109b681611b69565b600060fc81905560fd556040518181527fa2ec8d9db1d036a8700a09e8e0e537805f87edd54181a1fc08a71db281744b4e906020015b60405180910390a150565b60ca546001600160a01b03163314610a3b576040517f6efcc49f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a4481611b69565b50565b6060818067ffffffffffffffff811115610a6357610a636128ea565b604051908082528060200260200182016040528015610aa957816020015b604080518082019091526000815260606020820152815260200190600190039081610a815790505b5091503660005b82811015610ba957858582818110610aca57610aca612b74565b9050602002810190610adc9190612bb6565b91506000848281518110610af257610af2612b74565b60200260200101519050306001600160a01b0316838060200190610b169190612bf4565b604051610b24929190612c60565b600060405180830381855af49150503d8060008114610b5f576040519150601f19603f3d011682016040523d82523d6000602084013e610b64565b606091505b5060208301521515808252833517610ba0577f4d6a23280000000000000000000000000000000000000000000000000000000060005260046000fd5b50600101610ab0565b50505092915050565b610bba611af5565b565b60655433906001600160a01b03168114610c5d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f74207468652060448201527f6e6577206f776e6572000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b610a4481611ba7565b610c6e611af5565b60fc546000819003610cac576040517ff07e7d8b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600060fc81905560fd556040518181527fc9b788a7a7ebe95a0a3f82c9850959f0cc1657d1fb19a05ad1cf60877651725f906020016109ec565b60cb546001600160a01b03163314610d2a576040517fdbc2fa8500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b63ffffffff8216600090815260cc602052604081205460ff166002811115610d5457610d5461261f565b14610d8b576040517fd9d49b4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b63ffffffff8116600090815260cc602052604081205460ff166002811115610db557610db561261f565b14610dec576040517f6893014300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604080516060808201835263ffffffff808616835284811660208401908152600084860181815260cd8054600181810183559382905296517f83978b4c69c48dd978ab43fe30f077615294f938fb7f936d9eb340e51ea7db2e909701805494519251861668010000000000000000027fffffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffff938716640100000000027fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000090961698909616979097179390931716929092179093559154835191820190935290819081526affffffffffffffffffffff83166020808301919091526000604092830181905263ffffffff8716815260cc909152208151815482907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001836002811115610f3957610f3961261f565b0217905550602082015181546040938401516001600160a01b03166c01000000000000000000000000026bffffffffffffffffffffffff6affffffffffffffffffffff909316610100029290921660ff9091161717905580516060810190915280600181526affffffffffffffffffffff83166020808301919091526000604092830181905263ffffffff8616815260cc909152208151815482907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600183600281111561100a5761100a61261f565b0217905550602082015181546040909301516001600160a01b03166c01000000000000000000000000026bffffffffffffffffffffffff6affffffffffffffffffffff909216610100029190911660ff909316929092179190911790557fd0672fae056abe2bf0637742527d49add67fdb68192a6c6f6bf86eac19fe0530611093600183612c70565b604080516affffffffffffffffffffff909216825263ffffffff808716602084015285169082015260600160405180910390a16106af8383611bd8565b600054610100900460ff16158080156110f05750600054600160ff909116105b8061110a5750303b15801561110a575060005460ff166001145b611196576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152608401610c54565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905580156111f457600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b6111ff848484611c59565b611207611d47565b801561126a57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50505050565b60408083015163ffffffff16600090815260ff60205220546001600160a01b031680158015906112b25750836001600160a01b0316816001600160a01b031614155b156112e9576040517f4ae22ee400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006112fe8460000151856020015187611de6565b9050600060fb5490508061131f866040015163ffffffff1684876020611e1d565b14611356576040517f4cc472e700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0383166113c9576040858101805163ffffffff908116600090815260ff602090815284822080547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b038d169081179091559351938252610100905292909220911690555b600081815260fe602090815260408083206001600160a01b038a1684529091529020855181548792919082907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600183600581111561142b5761142b61261f565b021790555060208281015182546040948501517fffffffffffffffffffffffffffffffffffffffffffffff0000000000000000ff90911661010063ffffffff938416027fffffffffffffffffffffffffffffffffffffffffffffff00000000ffffffffff1617650100000000009183169190910217909255870151875192516001600160a01b038a169391909216917f8f9b8b0f4f062833bec85ea9a8465e4a1207b4be6eb565bbd0ae8b913588d04e916114e591612c9b565b60405180910390a36005855160058111156115025761150261261f565b0361151557611515856040015133611ec5565b505050505050565b611525611af5565b60ca54604080517f4098915200000000000000000000000000000000000000000000000000000000815290516000926001600160a01b03169163409891529160048083019260609291908290030181865afa158015611588573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ac9190612cbe565b505090508064ffffffffff166138406115c59190612ba3565b4210156115fe576040517f5be16c4600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000829003611639576040517f87c758ba00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60fc8290554260fd556040518281527fc222e0af9f2301ee0bfafe1044550b0553f5bdc4a65cb92cc2568820b5bf29449060200160405180910390a15050565b60008060008060608060cd8054905087106116c0576040517f1390f2a100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600060cd88815481106116d5576116d5612b74565b6000918252602080832060408051606081018252939091015463ffffffff8082168086526401000000008304821686860190815268010000000000000000909304821686850152865260ff9093528185205490519092168452909220546001600160a01b03928316995090925016604082015190965063ffffffff16156117ae5760408082015163ffffffff16600090815260ff60205220546001600160a01b031660408281015163ffffffff16600090815260cc60205220549095506c0100000000000000000000000090046001600160a01b031693505b60cb546040517fc495912b000000000000000000000000000000000000000000000000000000008152600481018a90526001600160a01b039091169063c495912b90602401600060405180830381865afa158015611810573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526118569190810190612d87565b97999698509496939592505050565b61186d611af5565b606580546001600160a01b0383167fffffffffffffffffffffffff000000000000000000000000000000000000000090911681179091556118b66033546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b60006118f9466118fe565b905090565b600063ffffffff821115611994576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201527f32206269747300000000000000000000000000000000000000000000000000006064820152608401610c54565b5090565b60006119a383611a59565b90506119ae816121d6565b8363ffffffff16816020015163ffffffff16146119f7576040517f1612d2ee00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b826001600160a01b03168463ffffffff167f8f9b8b0f4f062833bec85ea9a8465e4a1207b4be6eb565bbd0ae8b913588d04e6004604051611a389190612c9b565b60405180910390a3611a4e816040015183611ec5565b61126a848484612243565b60408051606080820183526000808352602080840182905283850182905260fb54825260fe81528482206001600160a01b038716835290528390208351918201909352825491929091829060ff166005811115611ab857611ab861261f565b6005811115611ac957611ac961261f565b8152905463ffffffff610100820481166020840152650100000000009091041660409091015292915050565b6033546001600160a01b03163314610bba576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610c54565b8060fb5414610a445760fb8190556040518181527f2cbc14f49c068133583f7cb530018af451c87c1cf1327cf2a4ff4698c4730aa4906020016109ec565b606580547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055610a4481612378565b60ca546040517fa2155c3400000000000000000000000000000000000000000000000000000000815263ffffffff8085166004830152831660248201526001600160a01b039091169063a2155c34906044015b600060405180830381600087803b158015611c4557600080fd5b505af1158015611515573d6000803e3d6000fd5b600054610100900460ff16611cf0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610c54565b60c980546001600160a01b039485167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161790915560ca80549385169382169390931790925560cb8054919093169116179055565b600054610100900460ff16611dde576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610c54565b610bba6123e2565b6000838383604051602001611dfd93929190612deb565b6040516020818303038152906040528051906020012090505b9392505050565b815160009082811115611e5c576040517fc5360feb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b84915060005b81811015611e9957611e8f83868381518110611e8057611e80612b74565b60200260200101518984612482565b9250600101611e62565b50805b83811015611ebb57611eb18360008984612482565b9250600101611e9c565b5050949350505050565b63ffffffff8216600090815260cc60205260408082208151606081019092528054829060ff166002811115611efc57611efc61261f565b6002811115611f0d57611f0d61261f565b8152905461010081046affffffffffffffffffffff1660208301526c0100000000000000000000000090046001600160a01b03166040909101529050600281516002811115611f5e57611f5e61261f565b03611f95576040517ff10068b500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60028082526001600160a01b03831660408084019190915263ffffffff8516600090815260cc6020522082518154849383917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016906001908490811115611ffe57611ffe61261f565b021790555060208281015182546040909401516001600160a01b03166c01000000000000000000000000026bffffffffffffffffffffffff6affffffffffffffffffffff928316610100021660ff909516949094179390931790915582015160009116156121cc576000600183602001516120799190612c70565b6affffffffffffffffffffff169050600060cd828154811061209d5761209d612b74565b600091825260209182902060408051606081018252919092015463ffffffff808216835264010000000082048116948301949094526801000000000000000090049092169082015260cd80549192508791849081106120fe576120fe612b74565b60009182526020918290200180547fffffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffff166801000000000000000063ffffffff9485160217905582015187821691161461215b57806020015161215e565b80515b63ffffffff818116600081815260cc60209081526040808320929092558151878152938b16908401528201526001600160a01b03871660608201529093507fb4cad5624e1d1c6c622ec70516ee582fe3f6519440c5b47e5165141edc9c54cf9060800160405180910390a150505b61126a84826124ab565b6001815160058111156121eb576121eb61261f565b1415801561220c57506002815160058111156122095761220961261f565b14155b15610a44576040517fec3d0d8500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60c9546040805163ffffffff861660248201526001600160a01b03858116604483015284811660648084019190915283518084039091018152608490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f9d228a510000000000000000000000000000000000000000000000000000000017905291517fa1c702a7000000000000000000000000000000000000000000000000000000008152919092169163a1c702a79161232f917f000000000000000000000000000000000000000000000000000000000000000091620151809190600401612e63565b60408051808303816000875af115801561234d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123719190612e95565b5050505050565b603380546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff16612479576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610c54565b610bba33611ba7565b6000600183831c1681036124a15761249a8585612502565b9050610658565b61249a8486612502565b60ca546040517f6116921800000000000000000000000000000000000000000000000000000000815263ffffffff8085166004830152831660248201526001600160a01b0390911690636116921890604401611c2b565b600082158015612510575081155b1561251d5750600061254a565b60408051602081018590529081018390526060016040516020818303038152906040528051906020012090505b92915050565b63ffffffff81168114610a4457600080fd5b80356001600160a01b038116811461075157600080fd5b6000806000806080858703121561258f57600080fd5b843561259a81612550565b9350602085013592506125af60408601612562565b9396929550929360600135925050565b6000806000606084860312156125d457600080fd5b83356125df81612550565b92506125ed60208501612562565b91506125fb60408501612562565b90509250925092565b60006020828403121561261657600080fd5b611e1682612562565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6006811061265e5761265e61261f565b9052565b61266d82825161264e565b60208181015163ffffffff9081169184019190915260409182015116910152565b6060810161254a8284612662565b6000602082840312156126ae57600080fd5b5035919050565b6001600160a01b038316815260808101611e166020830184612662565b60808101600386106126e6576126e661261f565b9481526001600160a01b0393841660208201529190921660408201526060015290565b60005b8381101561272457818101518382015260200161270c565b50506000910152565b60008151808452612745816020860160208601612709565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b602081526000611e16602083018461272d565b6000806020838503121561279d57600080fd5b823567ffffffffffffffff808211156127b557600080fd5b818501915085601f8301126127c957600080fd5b8135818111156127d857600080fd5b8660208260051b85010111156127ed57600080fd5b60209290920196919550909350505050565b60006020808301818452808551808352604092508286019150828160051b87010184880160005b83811015612885578883037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc001855281518051151584528701518784018790526128728785018261272d565b9588019593505090860190600101612826565b509098975050505050505050565b600080604083850312156128a657600080fd5b82356128b181612550565b915060208301356128c181612550565b809150509250929050565b6000806000606084860312156128e157600080fd5b6125df84612562565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040516060810167ffffffffffffffff8111828210171561293c5761293c6128ea565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715612989576129896128ea565b604052919050565b600082601f8301126129a257600080fd5b8135602067ffffffffffffffff8211156129be576129be6128ea565b8160051b6129cd828201612942565b92835284810182019282810190878511156129e757600080fd5b83870192505b84831015612a06578235825291830191908301906129ed565b979650505050505050565b600080600083850360a0811215612a2757600080fd5b612a3085612562565b935060607fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe082011215612a6257600080fd5b50612a6b612919565b602085013560068110612a7d57600080fd5b81526040850135612a8d81612550565b60208201526060850135612aa081612550565b60408201529150608084013567ffffffffffffffff811115612ac157600080fd5b612acd86828701612991565b9150509250925092565b60006001600160a01b0380891683528088166020840152808716604084015280861660608401525060c06080830152612b1360c083018561272d565b82810360a0840152612b25818561272d565b9998505050505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561254a5761254a612b32565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b8082018082111561254a5761254a612b32565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc1833603018112612bea57600080fd5b9190910192915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112612c2957600080fd5b83018035915067ffffffffffffffff821115612c4457600080fd5b602001915036819003821315612c5957600080fd5b9250929050565b8183823760009101908152919050565b6affffffffffffffffffffff828116828216039080821115612c9457612c94612b32565b5092915050565b6020810161254a828461264e565b805164ffffffffff8116811461075157600080fd5b600080600060608486031215612cd357600080fd5b612cdc84612ca9565b9250612cea60208501612ca9565b91506040840151612cfa81612550565b809150509250925092565b600082601f830112612d1657600080fd5b815167ffffffffffffffff811115612d3057612d306128ea565b612d6160207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601612942565b818152846020838601011115612d7657600080fd5b610658826020830160208701612709565b60008060408385031215612d9a57600080fd5b825167ffffffffffffffff80821115612db257600080fd5b612dbe86838701612d05565b93506020850151915080821115612dd457600080fd5b50612de185828601612d05565b9150509250929050565b600060068510612dfd57612dfd61261f565b5060f89390931b835260e09190911b7fffffffff0000000000000000000000000000000000000000000000000000000016600183015260601b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016600582015260190190565b600063ffffffff808616835280851660208401525060606040830152612e8c606083018461272d565b95945050505050565b60008060408385031215612ea857600080fd5b8251612eb381612550565b602093909301519294929350505056fea26469706673582212202cd7f64fbed7d2d5a15ae202ffa21ddd5e1608220a88cade750cad4af8a8be4a64736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"163146:10103:0:-:0;;;164423:157;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;149527:172;;;;;;;;;;;;;-1:-1:-1;;;149527:172:0;;;;88074:32;;164481:14;149527:172;88340:24;88354:8;88340:24;:::i;:::-;88332:32;;;;;;88028:343;149630:22:::1;:20;;;;;:22;;:::i;:::-;149616:36;::::0;;::::1;;::::0;;;149662:30;;::::1;;::::0;164511:29;::::1;::::0;;;-1:-1:-1;164507:66:0::1;;164549:24;;-1:-1:-1::0;;;164549:24:0::1;;;;;;;;;;;164507:66;164423:157:::0;163146:10103;;89915:98;89957:6;89982:24;:13;:22;;;;;:24;;:::i;:::-;89975:31;;89915:98;:::o;56036:187::-;56092:6;56127:16;56118:25;;;56110:76;;;;-1:-1:-1;;;56110:76:0;;803:2:1;56110:76:0;;;785:21:1;842:2;822:18;;;815:30;881:34;861:18;;;854:62;-1:-1:-1;;;932:18:1;;;925:36;978:19;;56110:76:0;;;;;;;;-1:-1:-1;56210:5:0;56036:187::o;14:280:1:-;83:6;136:2;124:9;115:7;111:23;107:32;104:52;;;152:1;149;142:12;104:52;184:9;178:16;234:10;227:5;223:22;216:5;213:33;203:61;;260:1;257;250:12;203:61;283:5;14:280;-1:-1:-1;;;14:280:1:o;299:297::-;417:12;;464:4;453:16;;;447:23;;417:12;482:16;;479:111;;;576:1;572:6;562;556:4;552:17;549:1;545:25;541:38;534:5;530:50;521:59;;479:111;;299:297;;;:::o;601:402::-;163146:10103:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","srcMapRuntime":"163146:10103:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;168848:849;;;;;;:::i;:::-;;:::i;:::-;;;976:66:1;964:79;;;946:98;;934:2;919:18;168848:849:0;;;;;;;;154879:136;;;;;;:::i;:::-;;:::i;:::-;;155630:417;;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;155389:201::-;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;:::i;157067:633::-;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;:::i;163576:24::-;;;;;;;;;3821:25:1;;;3809:2;3794:18;163576:24:0;3675:177:1;166197:448:0;;;:::i;156087:101::-;156165:9;:16;156087:101;;170079:163;170194:18;;170214:20;;170079:163;;;4213:25:1;;;4269:2;4254:18;;4247:34;;;;4186:18;170079:163:0;4039:248:1;88377:401:0;88548:28;;;;;;;;88561:7;88548:28;;88570:5;88548:28;;;;88377:401;;;;88548:28;88377:401;:::i;168256:220::-;;;;;;:::i;:::-;;:::i;85724:1352::-;;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;149924:57::-;;;:::i;149042:37::-;;;;;;;;7215:10:1;7203:23;;;7185:42;;7173:2;7158:18;149042:37:0;7041:192:1;147068:212:0;;;:::i;148925:35::-;;;;;143399:85;143471:6;;-1:-1:-1;;;;;143471:6:0;143399:85;;;-1:-1:-1;;;;;7402:55:1;;;7384:74;;7372:2;7357:18;143399:85:0;7238:226:1;165566:313:0;;;:::i;151778:21::-;;;;;-1:-1:-1;;;;;151778:21:0;;;153539:1300;;;;;;:::i;:::-;;:::i;151806:26::-;;;;;-1:-1:-1;;;;;151806:26:0;;;164586:194;;;;;;:::i;:::-;;:::i;167013:1195::-;;;;;;:::i;:::-;;:::i;165152:366::-;;;;;;:::i;:::-;;:::i;146181:99::-;146260:13;;-1:-1:-1;;;;;146260:13:0;146181:99;;156228:799;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;;;:::i;146473:178::-;;;;;;:::i;:::-;;:::i;151839:20::-;;;;;-1:-1:-1;;;;;151839:20:0;;;168848:849;169091:11;;168986:17;;-1:-1:-1;;;;;169091:11:0;169077:10;:25;169073:60;;169111:22;;;;;;;;;;;;;;169073:60;169245:13;169232:26;;:9;:26;;;169228:60;;169267:21;;;;;;;;;;;;;;169228:60;29667:6;169428:41;;169424:84;;;169478:30;;;;;;;;;;;;;;169424:84;169534:6;;169518:55;;;;;-1:-1:-1;;;;;11754:55:1;;;169518::0;;;11736:74:1;11826:18;;;11819:34;;;169534:6:0;;;;169518:36;;11709:18:1;;169518:55:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;169658:32:0;;-1:-1:-1;;;;168848:849:0;;;;;;;:::o;154879:136::-;152206:5;;-1:-1:-1;;;;;152206:5:0;152192:10;:19;152188:48;;152220:16;;;;;;;;;;;;;;152188:48;154974:34:::1;154986:6;154994:5;155001:6;154974:11;:34::i;:::-;154879:136:::0;;;:::o;155630:417::-;-1:-1:-1;;;;;;;;;;;;;;;;;;;;;;;;;155733:25:0;155752:5;155733:18;:25::i;:::-;155724:34;-1:-1:-1;155925:19:0;155885:13;:31;155899:16;155909:5;-1:-1:-1;;;;;173220:20:0;173188:13;173220:20;;;:13;:20;;;;;;;173122:125;155899:16;155885:31;;;;;;;;;;;-1:-1:-1;155885:31:0;:36;;;:59;;;;;;;;:::i;:::-;;:95;;;;-1:-1:-1;155963:17:0;155948:11;;:32;;;;;;;;:::i;:::-;;;155885:95;155881:160;;;156010:20;155996:34;;155881:160;155630:417;;;:::o;155389:201::-;-1:-1:-1;;;;;;;;155445:13:0;-1:-1:-1;;;;;;;;;;;;;;;172886:13:0;172918:14;;;:7;:14;;;;;;-1:-1:-1;;;;;172918:14:0;;-1:-1:-1;155535:19:0;;155531:52;;155565:18;155577:5;155565:11;:18::i;:::-;155556:27;;155531:52;155389:201;;;:::o;157067:633::-;157152:16;157170:13;157185:19;157206:18;157240;157261:16;157271:5;-1:-1:-1;;;;;173220:20:0;173188:13;173220:20;;;:13;:20;;;;;;;173122:125;157261:16;157287:32;157322:25;;;:13;:25;;;;;;157287:60;;;;;;;;;;157240:37;;-1:-1:-1;157287:32:0;;:60;;157322:25;157287:60;;;;;;;;;;;;:::i;:::-;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;157287:60:0;;;;;;157364:17;;157405:24;;;;157452:23;;;;157364:17;;-1:-1:-1;157405:24:0;;-1:-1:-1;157439:36:0;;-1:-1:-1;157364:17:0;-1:-1:-1;157489:14:0;;157485:209;;157519:28;157550:9;157560:14;157573:1;157560:10;:14;:::i;:::-;157550:25;;;;;;;;:::i;:::-;;;;;;;;;;157519:56;;;;;;;;157550:25;;;;157519:56;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;157597:86:0;;157607:32;;:75;;157664:18;;157607:75;;;157642:7;:19;;;157607:75;157597:86;;172886:13;172918:14;;;:7;:14;;;;;;-1:-1:-1;;;;;172918:14:0;;172820:119;157597:86;157589:94;;157505:189;157485:209;157230:470;;157067:633;;;;;:::o;166197:448::-;143292:13;:11;:13::i;:::-;166285:18:::1;::::0;166262:20:::1;166317:17:::0;;;166313:52:::1;;166343:22;;;;;;;;;;;;;;166313:52;166397:20;::::0;:50:::1;::::0;29613:8:::1;::::0;166397:50:::1;:::i;:::-;166379:15;:68;166375:106;;;166456:25;;;;;;;;;;;;;;166375:106;166491:27;166505:12;166491:13;:27::i;:::-;166549:1;166528:18;:22:::0;;;166560:20:::1;:24:::0;166599:39:::1;::::0;3821:25:1;;;166599:39:0::1;::::0;3809:2:1;3794:18;166599:39:0::1;;;;;;;;166252:393;166197:448::o:0;168256:220::-;168392:11;;-1:-1:-1;;;;;168392:11:0;168378:10;:25;168374:60;;168412:22;;;;;;;;;;;;;;168374:60;168444:25;168458:10;168444:13;:25::i;:::-;168256:220;:::o;85724:1352::-;85784:27;85840:5;;85876:20;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;;;;;;;85876:20:0;;;;;;;;;;;;;;;;85862:34;;85906:19;85940:9;85935:1135;85959:6;85955:1;:10;85935:1135;;;85990:5;;85996:1;85990:8;;;;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;85982:16;;86012:20;86035:11;86047:1;86035:14;;;;;;;;:::i;:::-;;;;;;;86012:37;;86392:4;-1:-1:-1;;;;;86384:26:0;86411:5;:14;;;;;;;;:::i;:::-;86384:42;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;86363:17:0;;;86346:80;;;;;;86699:19;;86696:38;86686:301;;86863:66;86857:4;86850:80;86964:4;86958;86951:18;86686:301;-1:-1:-1;87042:3:0;;85935:1135;;;;85813:1263;;85724:1352;;;;:::o;149924:57::-;143292:13;:11;:13::i;:::-;149924:57::o;147068:212::-;146260:13;;141601:10;;-1:-1:-1;;;;;146260:13:0;147167:24;;147159:78;;;;;;;13953:2:1;147159:78:0;;;13935:21:1;13992:2;13972:18;;;13965:30;14031:34;14011:18;;;14004:62;14102:11;14082:18;;;14075:39;14131:19;;147159:78:0;;;;;;;;;147247:26;147266:6;147247:18;:26::i;165566:313::-;143292:13;:11;:13::i;:::-;165659:18:::1;::::0;165630:26:::1;165691:23:::0;;;165687:58:::1;;165723:22;;;;;;;;;;;;;;165687:58;165776:1;165755:18;:22:::0;;;165787:20:::1;:24:::0;165826:46:::1;::::0;3821:25:1;;;165826:46:0::1;::::0;3809:2:1;3794:18;165826:46:0::1;3675:177:1::0;153539:1300:0;152206:5;;-1:-1:-1;;;;;152206:5:0;152192:10;:19;152188:48;;152220:16;;;;;;;;;;;;;;152188:48;153690:25:::1;::::0;::::1;153724:16;153690:25:::0;;;:13:::1;:25;::::0;;;;:30;::::1;;:50;::::0;::::1;;;;;;:::i;:::-;;153686:79;;153749:16;;;;;;;;;;;;;;153686:79;153779:26;::::0;::::1;153814:16;153779:26:::0;;;:13:::1;:26;::::0;;;;:31;::::1;;:51;::::0;::::1;;;;;;:::i;:::-;;153775:81;;153839:17;;;;;;;;;;;;;;153775:81;153881:41;::::0;;::::1;::::0;;::::1;::::0;;::::1;::::0;;::::1;::::0;;;;::::1;;::::0;::::1;::::0;;;-1:-1:-1;153881:41:0;;;;;;153866:9:::1;:57:::0;;::::1;::::0;;::::1;::::0;;;;;;;;;;;::::1;::::0;;;;;;;::::1;::::0;::::1;::::0;;;::::1;::::0;::::1;::::0;;;;;;;::::1;::::0;;;;;;;::::1;;::::0;;;::::1;::::0;;;154348:16;;154403:57;;;;::::1;::::0;;;;;;;;::::1;::::0;::::1;;::::0;;::::1;::::0;;;;-1:-1:-1;154403:57:0;;;;;;;154375:25:::1;::::0;::::1;::::0;;:13:::1;:25:::0;;;;:85;;;;:25;;:85;::::1;::::0;;::::1;::::0;::::1;;;;;;:::i;:::-;;;::::0;;-1:-1:-1;154375:85:0::1;::::0;::::1;::::0;;;::::1;::::0;;::::1;::::0;-1:-1:-1;;;;;154375:85:0::1;::::0;::::1;::::0;::::1;::::0;;::::1;;;::::0;;;;;;;;;::::1;::::0;;154499:57;;::::1;::::0;::::1;::::0;;;;154375:85:::1;154499:57:::0;;::::1;::::0;::::1;;::::0;;::::1;::::0;;;;-1:-1:-1;154499:57:0;;;;;;;154470:26:::1;::::0;::::1;::::0;;:13:::1;:26:::0;;;;:86;;;;:26;;:86;::::1;::::0;;::::1;::::0;::::1;;;;;;:::i;:::-;;;::::0;;-1:-1:-1;154470:86:0::1;::::0;::::1;::::0;;;::::1;::::0;;::::1;::::0;-1:-1:-1;;;;;154470:86:0::1;::::0;::::1;::::0;::::1;::::0;;::::1;;;::::0;;;;;;;;;;;;;;;::::1;::::0;;154682:95:::1;154711:14;154470:86;154711:10:::0;:14:::1;:::i;:::-;154682:95;::::0;;14582:24:1;14570:37;;;14552:56;;14627:10;14673:15;;;14668:2;14653:18;;14646:43;14725:15;;14705:18;;;14698:43;14540:2;14525:18;154682:95:0::1;;;;;;;154787:45;154808:10;154820:11;154787:20;:45::i;164586:194::-:0;117566:19;117589:13;;;;;;117588:14;;117634:34;;;;-1:-1:-1;117652:12:0;;117667:1;117652:12;;;;:16;117634:34;117633:108;;;-1:-1:-1;117713:4:0;77592:19;:23;;;117674:66;;-1:-1:-1;117723:12:0;;;;;:17;117674:66;117612:201;;;;;;;14954:2:1;117612:201:0;;;14936:21:1;14993:2;14973:18;;;14966:30;15032:34;15012:18;;;15005:62;15103:16;15083:18;;;15076:44;15137:19;;117612:201:0;14752:410:1;117612:201:0;117823:12;:16;;;;117838:1;117823:16;;;117849:65;;;;117883:13;:20;;;;;;;;117849:65;164692:50:::1;164712:7;164721:12;164735:6;164692:19;:50::i;:::-;164752:21;:19;:21::i;:::-;117938:14:::0;117934:99;;;117984:5;117968:21;;;;;;118008:14;;-1:-1:-1;15319:36:1;;118008:14:0;;15307:2:1;15292:18;118008:14:0;;;;;;;117934:99;117556:483;164586:194;;;:::o;167013:1195::-;167155:12;;;;;167147:21;;167125:19;167147:21;;;:7;:21;;;;-1:-1:-1;;;;;167147:21:0;167182:25;;;;;:49;;;167226:5;-1:-1:-1;;;;;167211:20:0;:11;-1:-1:-1;;;;;167211:20:0;;;167182:49;167178:83;;;167240:21;;;;;;;;;;;;;;167178:83;167332:12;167347:45;167358:6;:11;;;167371:6;:13;;;167386:5;167347:10;:45::i;:::-;167332:60;;167402:12;167417:9;;167402:24;;167569:4;167499:66;167520:6;:12;;;167499:66;;167534:4;167540:5;26546:2;167499:20;:66::i;:::-;:74;167495:108;;167582:21;;;;;;;;;;;;;;167495:108;-1:-1:-1;;;;;167659:25:0;;167655:134;;167708:12;;;;;;167700:21;;;;;;;;:7;:21;;;;;;;:29;;;;-1:-1:-1;;;;;167700:29:0;;;;;;;;167766:12;;167743:20;;;167700:29;167743:20;;;;;;:35;;;;167655:134;167851:15;;;;:9;:15;;;;;;;;-1:-1:-1;;;;;167851:22:0;;;;;;;;;:31;;;;167876:6;;167851:22;:31;:22;;:31;;;;;;;;;;;;:::i;:::-;;;;;-1:-1:-1;167851:31:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;167924:13;;;167911:11;;167897:48;;-1:-1:-1;;;;;167897:48:0;;;;;;;;;;;;;:::i;:::-;;;;;;;;168047:17;168032:11;;:32;;;;;;;;:::i;:::-;;168028:174;;168150:41;168166:6;:12;;;168180:10;168150:15;:41::i;:::-;167115:1093;;;167013:1195;;;:::o;165152:366::-;143292:13;:11;:13::i;:::-;152422:11:::1;::::0;152401:46:::1;::::0;;;;;;;152376:19:::1;::::0;-1:-1:-1;;;;;152422:11:0::1;::::0;152401:44:::1;::::0;:46:::1;::::0;;::::1;::::0;::::1;::::0;;;;;;;;152422:11;152401:46:::1;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;152375:72;;;;152500:12;152479:33;;29974:7;152479:33;;;;:::i;:::-;152461:15;:51;152457:74;;;152521:10;;;;;;;;;;;;;;152457:74;165268:1:::2;165254:15:::0;;;165250:48:::2;;165278:20;;;;;;;;;;;;;;165250:48;165388:18;:31:::0;;;165452:15:::2;165429:20;:38:::0;165482:29:::2;::::0;3821:25:1;;;165482:29:0::2;::::0;3809:2:1;3794:18;165482:29:0::2;;;;;;;152285:264:::1;165152:366:::0;:::o;156228:799::-;156323:13;156350:14;156378:20;156412:19;156445:26;156485:28;156551:9;:16;;;;156542:5;:25;156538:55;;156576:17;;;;;;;;;;;;;;156538:55;156603:28;156634:9;156644:5;156634:16;;;;;;;;:::i;:::-;;;;;;;;;156603:47;;;;;;;;156634:16;;;;156603:47;;;;;;;;;;;;;;;;;;;;;;;;;;;;;172918:14;;:7;:14;;;;;;;156726:19;;156716:30;;;172918:14;;;;;;-1:-1:-1;;;;;172918:14:0;;;;-1:-1:-1;156603:47:0;;-1:-1:-1;172918:14:0;156760:20;;;;156707:39;;-1:-1:-1;156760:24:0;;;156756:176;;156825:20;;;;;156815:31;;172886:13;172918:14;;;:7;:14;;;;-1:-1:-1;;;;;172918:14:0;156888:20;;;;;156874:35;;;;;;:13;:35;;;:47;156800:46;;-1:-1:-1;156874:47:0;;;-1:-1:-1;;;;;156874:47:0;;-1:-1:-1;156756:176:0;156992:5;;156976:44;;;;;;;;3821:25:1;;;-1:-1:-1;;;;;156992:5:0;;;;156976:37;;3794:18:1;;156976:44:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;156228:799;;;;-1:-1:-1;156228:799:0;;;;;-1:-1:-1;;;156228:799:0:o;146473:178::-;143292:13;:11;:13::i;:::-;146562::::1;:24:::0;;-1:-1:-1;;;;;146562:24:0;::::1;::::0;;;::::1;::::0;::::1;::::0;;;146626:7:::1;143471:6:::0;;-1:-1:-1;;;;;143471:6:0;;143399:85;146626:7:::1;-1:-1:-1::0;;;;;146601:43:0::1;;;;;;;;;;;146473:178:::0;:::o;89915:98::-;89957:6;89982:24;:13;:22;:24::i;:::-;89975:31;;89915:98;:::o;56036:187::-;56092:6;56127:16;56118:25;;;56110:76;;;;;;;17511:2:1;56110:76:0;;;17493:21:1;17550:2;17530:18;;;17523:30;17589:34;17569:18;;;17562:62;17660:8;17640:18;;;17633:36;17686:19;;56110:76:0;17309:402:1;56110:76:0;-1:-1:-1;56210:5:0;56036:187::o;158883:775::-;159044:25;159072;159091:5;159072:18;:25::i;:::-;159044:53;;159107:30;:6;:28;:30::i;:::-;159168:6;159151:23;;:6;:13;;;:23;;;159147:58;;159183:22;;;;;;;;;;;;;;159147:58;159376:5;-1:-1:-1;;;;;159332:50:0;159368:6;159332:50;;;159346:20;159332:50;;;;;;:::i;:::-;;;;;;;;159458:37;159474:6;:12;;;159488:6;159458:15;:37::i;:::-;159610:41;159629:6;159637:5;159644:6;159610:18;:41::i;172489:146::-;-1:-1:-1;;;;;;;;;;;;;;;;;;;;;;;;;;172611:9:0;;172601:20;;:9;:20;;;;;-1:-1:-1;;;;;172601:27:0;;;;;;;;;172594:34;;;;;;;;;;-1:-1:-1;;172594:34:0;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;172489:146;-1:-1:-1;;172489:146:0:o;143557:130::-;143471:6;;-1:-1:-1;;;;;143471:6:0;141601:10;143620:23;143612:68;;;;;;;17918:2:1;143612:68:0;;;17900:21:1;;;17937:18;;;17930:30;17996:34;17976:18;;;17969:62;18048:18;;143612:68:0;17716:356:1;171851:186:0;171930:10;171917:9;;:23;171913:118;;171956:9;:22;;;171997:23;;3821:25:1;;;171997:23:0;;3809:2:1;3794:18;171997:23:0;3675:177:1;146835:153:0;146924:13;146917:20;;;;;;146947:34;146972:8;146947:24;:34::i;171214:233::-;171391:11;;171377:63;;;;;18257:10:1;18294:15;;;171377:63:0;;;18276:34:1;18346:15;;18326:18;;;18319:43;-1:-1:-1;;;;;171391:11:0;;;;171377:38;;18220:18:1;;171377:63:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;152930:203;119661:13;;;;;;;119653:69;;;;;;;18575:2:1;119653:69:0;;;18557:21:1;18614:2;18594:18;;;18587:30;18653:34;18633:18;;;18626:62;18724:13;18704:18;;;18697:41;18755:19;;119653:69:0;18373:407:1;119653:69:0;153050:6:::1;:16:::0;;-1:-1:-1;;;;;153050:16:0;;::::1;::::0;;;::::1;;::::0;;;153076:11:::1;:26:::0;;;;::::1;::::0;;::::1;::::0;;;::::1;::::0;;;153112:5:::1;:14:::0;;;;;::::1;::::0;::::1;;::::0;;152930:203::o;145796:100::-;119661:13;;;;;;;119653:69;;;;;;;18575:2:1;119653:69:0;;;18557:21:1;18614:2;18594:18;;;18587:30;18653:34;18633:18;;;18626:62;18724:13;18704:18;;;18697:41;18755:19;;119653:69:0;18373:407:1;119653:69:0;145863:26:::1;:24;:26::i;161221:170::-:0;161310:7;161363:4;161369:6;161377:5;161346:37;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;161336:48;;;;;;161329:55;;161221:170;;;;;;:::o;95545:900::-;95785:12;;95680:13;;95811:17;;;95807:48;;;95837:18;;;;;;;;;;;;;;95807:48;95873:4;95865:12;;96042:9;96037:189;96061:8;96057:1;:12;96037:189;;;96175:36;96185:5;96192;96198:1;96192:8;;;;;;;;:::i;:::-;;;;;;;96202:5;96209:1;96175:9;:36::i;:::-;96167:44;-1:-1:-1;96071:3:0;;96037:189;;;-1:-1:-1;96323:8:0;96306:123;96337:6;96333:1;:10;96306:123;;;96376:38;96386:5;96401:1;96405:5;96412:1;96376:9;:38::i;:::-;96368:46;-1:-1:-1;96345:3:0;;96306:123;;;;95699:746;95545:900;;;;;;:::o;159756:1078::-;159872:27;;;159837:32;159872:27;;;:13;:27;;;;;;159837:62;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;159837:62:0;;;;;;;-1:-1:-1;159934:19:0;159913:17;;:40;;;;;;;;:::i;:::-;;159909:77;;159962:24;;;;;;;;;;;;;;159909:77;160016:19;159996:39;;;-1:-1:-1;;;;;160045:33:0;;:24;;;;:33;;;;160088:27;;;-1:-1:-1;160088:27:0;;;:13;:27;;;:42;;;;159996:12;;160088:27;;:42;;;;;;;;;;;;;;:::i;:::-;;;;;-1:-1:-1;160088:42:0;;;;;;;;;;;;-1:-1:-1;;;;;160088:42:0;;;;;;;;;;;;;;;;;;;;;;;;;;160245:23;;;160088:42;;160245:28;;160241:529;;160289:20;160338:1;160312:12;:23;;;:27;;;;:::i;:::-;160289:50;;;;160353:28;160384:9;160394:12;160384:23;;;;;;;;:::i;:::-;;;;;;;;;;160353:54;;;;;;;;160384:23;;;;160353:54;;;;;;;;;;;;;;;;;;;;;;;;;;;;;160421:9;:23;;160353:54;;-1:-1:-1;160460:12:0;;160431;;160421:23;;;;;;:::i;:::-;;;;;;;;;;;:51;;;;;;;;;;;;;160553:19;;;:35;;;;;;:78;;160612:7;:19;;;160553:78;;;160591:18;;160553:78;160652:25;;;;;;;;:13;:25;;;;;;;;160645:32;;;;160696:63;;19568:25:1;;;19658:15;;;19638:18;;;19631:43;19690:18;;19683:43;-1:-1:-1;;;;;19762:55:1;;19757:2;19742:18;;19735:83;160652:25:0;;-1:-1:-1;160696:63:0;;19555:3:1;19540:19;160696:63:0;;;;;;;160275:495;;160241:529;160779:48;160802:12;160816:10;160779:22;:48::i;94093:223::-;94194:16;94179:11;;:31;;;;;;;;:::i;:::-;;;:69;;;;-1:-1:-1;94229:19:0;94214:11;;:34;;;;;;;;:::i;:::-;;;94179:69;94175:135;;;94271:28;;;;;;;;;;;;;;170564:569;170872:6;;171019:96;;;20059:10:1;20047:23;;171019:96:0;;;20029:42:1;-1:-1:-1;;;;;20168:15:1;;;20148:18;;;20141:43;20220:15;;;20200:18;;;;20193:43;;;;171019:96:0;;;;;;;;;;20002:18:1;;;;171019:96:0;;;;;;;;;171042:49;171019:96;;;170856:270;;;;;170872:6;;;;;170856:42;;:270;;170926:13;;29667:6;;171019:96;170856:270;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;170564:569;;;:::o;144624:187::-;144716:6;;;-1:-1:-1;;;;;144732:17:0;;;;;;;;;;;144764:40;;144716:6;;;144732:17;144716:6;;144764:40;;144697:16;;144764:40;144687:124;144624:187;:::o;143062:111::-;119661:13;;;;;;;119653:69;;;;;;;18575:2:1;119653:69:0;;;18557:21:1;18614:2;18594:18;;;18587:30;18653:34;18633:18;;;18626:62;18724:13;18704:18;;;18697:41;18755:19;;119653:69:0;18373:407:1;119653:69:0;143134:32:::1;141601:10:::0;143134:18:::1;:32::i;96827:526::-:0;96963:14;97168:1;97141:23;;;97140:29;:34;;97136:211;;97223:24;97233:4;97239:7;97223:9;:24::i;:::-;97216:31;;;;97136:211;97312:24;97322:7;97331:4;97312:9;:24::i;171530:240::-;171710:11;;171696:67;;;;;18257:10:1;18294:15;;;171696:67:0;;;18276:34:1;18346:15;;18326:18;;;18319:43;-1:-1:-1;;;;;171710:11:0;;;;171696:41;;18220:18:1;;171696:67:0;18077:291:1;97817:287:0;97898:14;97928:23;;:51;;;;-1:-1:-1;97955:24:0;;97928:51;97924:174;;;-1:-1:-1;98002:1:0;97995:8;;97924:174;98051:35;;;;;;21127:19:1;;;21162:12;;;21155:28;;;21199:12;;98051:35:0;;;;;;;;;;;;98041:46;;;;;;98034:53;;97924:174;97817:287;;;;:::o;14:121:1:-;99:10;92:5;88:22;81:5;78:33;68:61;;125:1;122;115:12;140:196;208:20;;-1:-1:-1;;;;;257:54:1;;247:65;;237:93;;326:1;323;316:12;341:456;426:6;434;442;450;503:3;491:9;482:7;478:23;474:33;471:53;;;520:1;517;510:12;471:53;559:9;546:23;578:30;602:5;578:30;:::i;:::-;627:5;-1:-1:-1;679:2:1;664:18;;651:32;;-1:-1:-1;702:38:1;736:2;721:18;;702:38;:::i;:::-;341:456;;;;-1:-1:-1;692:48:1;;787:2;772:18;759:32;;-1:-1:-1;;341:456:1:o;1055:393::-;1131:6;1139;1147;1200:2;1188:9;1179:7;1175:23;1171:32;1168:52;;;1216:1;1213;1206:12;1168:52;1255:9;1242:23;1274:30;1298:5;1274:30;:::i;:::-;1323:5;-1:-1:-1;1347:38:1;1381:2;1366:18;;1347:38;:::i;:::-;1337:48;;1404:38;1438:2;1427:9;1423:18;1404:38;:::i;:::-;1394:48;;1055:393;;;;;:::o;1453:186::-;1512:6;1565:2;1553:9;1544:7;1540:23;1536:32;1533:52;;;1581:1;1578;1571:12;1533:52;1604:29;1623:9;1604:29;:::i;1644:184::-;1696:77;1693:1;1686:88;1793:4;1790:1;1783:15;1817:4;1814:1;1807:15;1833:140;1914:1;1907:5;1904:12;1894:46;;1920:18;;:::i;:::-;1949;;1833:140::o;1978:315::-;2043:44;2083:3;2075:5;2069:12;2043:44;:::i;:::-;2133:4;2122:16;;;2116:23;2158:10;2200:21;;;2184:14;;;2177:45;;;;2275:4;2264:16;;;2258:23;2254:32;2238:14;;2231:56;1978:315::o;2298:258::-;2490:2;2475:18;;2502:48;2479:9;2532:6;2502:48;:::i;2561:180::-;2620:6;2673:2;2661:9;2652:7;2648:23;2644:32;2641:52;;;2689:1;2686;2679:12;2641:52;-1:-1:-1;2712:23:1;;2561:180;-1:-1:-1;2561:180:1:o;2746:379::-;-1:-1:-1;;;;;2997:55:1;;2979:74;;2966:3;2951:19;;3062:57;3115:2;3100:18;;3092:6;3062:57;:::i;3130:540::-;3362:3;3347:19;;3396:1;3385:13;;3375:47;;3402:18;;:::i;:::-;3431:25;;;-1:-1:-1;;;;;3553:15:1;;;3548:2;3533:18;;3526:43;3605:15;;;;3600:2;3585:18;;3578:43;3652:2;3637:18;3630:34;3130:540;:::o;4292:250::-;4377:1;4387:113;4401:6;4398:1;4395:13;4387:113;;;4477:11;;;4471:18;4458:11;;;4451:39;4423:2;4416:10;4387:113;;;-1:-1:-1;;4534:1:1;4516:16;;4509:27;4292:250::o;4547:330::-;4589:3;4627:5;4621:12;4654:6;4649:3;4642:19;4670:76;4739:6;4732:4;4727:3;4723:14;4716:4;4709:5;4705:16;4670:76;:::i;:::-;4791:2;4779:15;4796:66;4775:88;4766:98;;;;4866:4;4762:109;;4547:330;-1:-1:-1;;4547:330:1:o;4882:220::-;5031:2;5020:9;5013:21;4994:4;5051:45;5092:2;5081:9;5077:18;5069:6;5051:45;:::i;5292:639::-;5402:6;5410;5463:2;5451:9;5442:7;5438:23;5434:32;5431:52;;;5479:1;5476;5469:12;5431:52;5519:9;5506:23;5548:18;5589:2;5581:6;5578:14;5575:34;;;5605:1;5602;5595:12;5575:34;5643:6;5632:9;5628:22;5618:32;;5688:7;5681:4;5677:2;5673:13;5669:27;5659:55;;5710:1;5707;5700:12;5659:55;5750:2;5737:16;5776:2;5768:6;5765:14;5762:34;;;5792:1;5789;5782:12;5762:34;5845:7;5840:2;5830:6;5827:1;5823:14;5819:2;5815:23;5811:32;5808:45;5805:65;;;5866:1;5863;5856:12;5805:65;5897:2;5889:11;;;;;5919:6;;-1:-1:-1;5292:639:1;;-1:-1:-1;;;;5292:639:1:o;5936:1100::-;6126:4;6155:2;6195;6184:9;6180:18;6225:2;6214:9;6207:21;6248:6;6283;6277:13;6314:6;6306;6299:22;6340:2;6330:12;;6373:2;6362:9;6358:18;6351:25;;6435:2;6425:6;6422:1;6418:14;6407:9;6403:30;6399:39;6473:2;6465:6;6461:15;6494:1;6504:503;6518:6;6515:1;6512:13;6504:503;;;6583:22;;;6607:66;6579:95;6567:108;;6698:13;;6753:9;;6746:17;6739:25;6724:41;;6804:11;;6798:18;6836:15;;;6829:27;;;6879:48;6911:15;;;6798:18;6879:48;:::i;:::-;6985:12;;;;6869:58;-1:-1:-1;;6950:15:1;;;;6540:1;6533:9;6504:503;;;-1:-1:-1;7024:6:1;;5936:1100;-1:-1:-1;;;;;;;;5936:1100:1:o;7469:384::-;7535:6;7543;7596:2;7584:9;7575:7;7571:23;7567:32;7564:52;;;7612:1;7609;7602:12;7564:52;7651:9;7638:23;7670:30;7694:5;7670:30;:::i;:::-;7719:5;-1:-1:-1;7776:2:1;7761:18;;7748:32;7789;7748;7789;:::i;:::-;7840:7;7830:17;;;7469:384;;;;;:::o;7858:334::-;7935:6;7943;7951;8004:2;7992:9;7983:7;7979:23;7975:32;7972:52;;;8020:1;8017;8010:12;7972:52;8043:29;8062:9;8043:29;:::i;8197:184::-;8249:77;8246:1;8239:88;8346:4;8343:1;8336:15;8370:4;8367:1;8360:15;8386:253;8458:2;8452:9;8500:4;8488:17;;8535:18;8520:34;;8556:22;;;8517:62;8514:88;;;8582:18;;:::i;:::-;8618:2;8611:22;8386:253;:::o;8644:334::-;8715:2;8709:9;8771:2;8761:13;;8776:66;8757:86;8745:99;;8874:18;8859:34;;8895:22;;;8856:62;8853:88;;;8921:18;;:::i;:::-;8957:2;8950:22;8644:334;;-1:-1:-1;8644:334:1:o;8983:712::-;9037:5;9090:3;9083:4;9075:6;9071:17;9067:27;9057:55;;9108:1;9105;9098:12;9057:55;9144:6;9131:20;9170:4;9193:18;9189:2;9186:26;9183:52;;;9215:18;;:::i;:::-;9261:2;9258:1;9254:10;9284:28;9308:2;9304;9300:11;9284:28;:::i;:::-;9346:15;;;9416;;;9412:24;;;9377:12;;;;9448:15;;;9445:35;;;9476:1;9473;9466:12;9445:35;9512:2;9504:6;9500:15;9489:26;;9524:142;9540:6;9535:3;9532:15;9524:142;;;9606:17;;9594:30;;9557:12;;;;9644;;;;9524:142;;;9684:5;8983:712;-1:-1:-1;;;;;;;8983:712:1:o;9700:1088::-;9831:6;9839;9847;9891:9;9882:7;9878:23;9921:3;9917:2;9913:12;9910:32;;;9938:1;9935;9928:12;9910:32;9961:29;9980:9;9961:29;:::i;:::-;9951:39;;10083:4;10014:66;10010:2;10006:75;10002:86;9999:106;;;10101:1;10098;10091:12;9999:106;;10127:22;;:::i;:::-;10201:2;10190:9;10186:18;10173:32;10236:1;10227:7;10224:14;10214:42;;10252:1;10249;10242:12;10214:42;10265:22;;10339:2;10324:18;;10311:32;10352;10311;10352;:::i;:::-;10411:2;10400:14;;10393:31;10476:4;10461:20;;10448:34;10491:32;10448:34;10491:32;:::i;:::-;10550:2;10539:14;;10532:31;10543:5;-1:-1:-1;10638:3:1;10623:19;;10610:33;10666:18;10655:30;;10652:50;;;10698:1;10695;10688:12;10652:50;10721:61;10774:7;10765:6;10754:9;10750:22;10721:61;:::i;:::-;10711:71;;;9700:1088;;;;;:::o;10793:764::-;11061:4;-1:-1:-1;;;;;11171:2:1;11163:6;11159:15;11148:9;11141:34;11223:2;11215:6;11211:15;11206:2;11195:9;11191:18;11184:43;11275:2;11267:6;11263:15;11258:2;11247:9;11243:18;11236:43;11327:2;11319:6;11315:15;11310:2;11299:9;11295:18;11288:43;;11368:3;11362;11351:9;11347:19;11340:32;11395:46;11436:3;11425:9;11421:19;11413:6;11395:46;:::i;:::-;11490:9;11482:6;11478:22;11472:3;11461:9;11457:19;11450:51;11518:33;11544:6;11536;11518:33;:::i;:::-;11510:41;10793:764;-1:-1:-1;;;;;;;;;10793:764:1:o;11864:184::-;11916:77;11913:1;11906:88;12013:4;12010:1;12003:15;12037:4;12034:1;12027:15;12053:128;12120:9;;;12141:11;;;12138:37;;;12155:18;;:::i;12186:184::-;12238:77;12235:1;12228:88;12335:4;12332:1;12325:15;12359:4;12356:1;12349:15;12375:125;12440:9;;;12461:10;;;12458:36;;;12474:18;;:::i;12505:380::-;12595:4;12653:11;12640:25;12743:66;12732:8;12716:14;12712:29;12708:102;12688:18;12684:127;12674:155;;12825:1;12822;12815:12;12674:155;12846:33;;;;;12505:380;-1:-1:-1;;12505:380:1:o;12890:580::-;12967:4;12973:6;13033:11;13020:25;13123:66;13112:8;13096:14;13092:29;13088:102;13068:18;13064:127;13054:155;;13205:1;13202;13195:12;13054:155;13232:33;;13284:20;;;-1:-1:-1;13327:18:1;13316:30;;13313:50;;;13359:1;13356;13349:12;13313:50;13392:4;13380:17;;-1:-1:-1;13423:14:1;13419:27;;;13409:38;;13406:58;;;13460:1;13457;13450:12;13406:58;12890:580;;;;;:::o;13475:271::-;13658:6;13650;13645:3;13632:33;13614:3;13684:16;;13709:13;;;13684:16;13475:271;-1:-1:-1;13475:271:1:o;14161:189::-;14229:24;14286:10;;;14274;;;14270:27;;14309:12;;;14306:38;;;14324:18;;:::i;:::-;14306:38;14161:189;;;;:::o;15366:208::-;15512:2;15497:18;;15524:44;15501:9;15550:6;15524:44;:::i;15579:169::-;15657:13;;15710:12;15699:24;;15689:35;;15679:63;;15738:1;15735;15728:12;15753:415;15838:6;15846;15854;15907:2;15895:9;15886:7;15882:23;15878:32;15875:52;;;15923:1;15920;15913:12;15875:52;15946:39;15975:9;15946:39;:::i;:::-;15936:49;;16004:48;16048:2;16037:9;16033:18;16004:48;:::i;:::-;15994:58;;16095:2;16084:9;16080:18;16074:25;16108:30;16132:5;16108:30;:::i;:::-;16157:5;16147:15;;;15753:415;;;;;:::o;16173:568::-;16226:5;16279:3;16272:4;16264:6;16260:17;16256:27;16246:55;;16297:1;16294;16287:12;16246:55;16326:6;16320:13;16352:18;16348:2;16345:26;16342:52;;;16374:18;;:::i;:::-;16418:114;16526:4;16457:66;16450:4;16446:2;16442:13;16438:86;16434:97;16418:114;:::i;:::-;16557:2;16548:7;16541:19;16603:3;16596:4;16591:2;16583:6;16579:15;16575:26;16572:35;16569:55;;;16620:1;16617;16610:12;16569:55;16633:77;16707:2;16700:4;16691:7;16687:18;16680:4;16672:6;16668:17;16633:77;:::i;16746:558::-;16843:6;16851;16904:2;16892:9;16883:7;16879:23;16875:32;16872:52;;;16920:1;16917;16910:12;16872:52;16953:9;16947:16;16982:18;17023:2;17015:6;17012:14;17009:34;;;17039:1;17036;17029:12;17009:34;17062:60;17114:7;17105:6;17094:9;17090:22;17062:60;:::i;:::-;17052:70;;17168:2;17157:9;17153:18;17147:25;17131:41;;17197:2;17187:8;17184:16;17181:36;;;17213:1;17210;17203:12;17181:36;;17236:62;17290:7;17279:8;17268:9;17264:24;17236:62;:::i;:::-;17226:72;;;16746:558;;;;;:::o;18785:551::-;18962:3;19001:1;18993:6;18990:13;18980:47;;19007:18;;:::i;:::-;-1:-1:-1;19052:3:1;19048:16;;;;19036:29;;19102:3;19098:16;;;;19116:66;19094:89;19090:1;19081:11;;19074:110;19221:2;19217:15;19234:66;19213:88;19209:1;19200:11;;19193:109;19327:2;19318:12;;18785:551::o;20247:403::-;20409:4;20438:10;20487:2;20479:6;20475:15;20464:9;20457:34;20539:2;20531:6;20527:15;20522:2;20511:9;20507:18;20500:43;;20579:2;20574;20563:9;20559:18;20552:30;20599:45;20640:2;20629:9;20625:18;20617:6;20599:45;:::i;:::-;20591:53;20247:403;-1:-1:-1;;;;;20247:403:1:o;20655:310::-;20733:6;20741;20794:2;20782:9;20773:7;20769:23;20765:32;20762:52;;;20810:1;20807;20800:12;20762:52;20842:9;20836:16;20861:30;20885:5;20861:30;:::i;:::-;20955:2;20940:18;;;;20934:25;20910:5;;20934:25;;-1:-1:-1;;;20655:310:1:o","abiDefinition":[{"inputs":[{"internalType":"uint32","name":"synapseDomain_","type":"uint32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AgentNotActiveNorUnstaking","type":"error"},{"inputs":[],"name":"AgentRootNotProposed","type":"error"},{"inputs":[],"name":"AgentRootTimeoutNotOver","type":"error"},{"inputs":[],"name":"CallerNotDestination","type":"error"},{"inputs":[],"name":"CallerNotInbox","type":"error"},{"inputs":[],"name":"DisputeAlreadyResolved","type":"error"},{"inputs":[],"name":"GuardInDispute","type":"error"},{"inputs":[],"name":"IncorrectAgentDomain","type":"error"},{"inputs":[],"name":"IncorrectAgentIndex","type":"error"},{"inputs":[],"name":"IncorrectAgentProof","type":"error"},{"inputs":[],"name":"IncorrectAgentRoot","type":"error"},{"inputs":[],"name":"IncorrectVersionLength","type":"error"},{"inputs":[],"name":"IndexOutOfRange","type":"error"},{"inputs":[],"name":"MustBeSynapseDomain","type":"error"},{"inputs":[],"name":"NotStuck","type":"error"},{"inputs":[],"name":"NotaryInDispute","type":"error"},{"inputs":[],"name":"SynapseDomainForbidden","type":"error"},{"inputs":[],"name":"TreeHeightTooLow","type":"error"},{"inputs":[],"name":"WithdrawTipsOptimisticPeriod","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"newRoot","type":"bytes32"}],"name":"AgentRootProposed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"disputeIndex","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"guardIndex","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"notaryIndex","type":"uint32"}],"name":"DisputeOpened","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"disputeIndex","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"slashedIndex","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"rivalIndex","type":"uint32"},{"indexed":false,"internalType":"address","name":"fraudProver","type":"address"}],"name":"DisputeResolved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"proposedRoot","type":"bytes32"}],"name":"ProposedAgentRootCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"proposedRoot","type":"bytes32"}],"name":"ProposedAgentRootResolved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"newRoot","type":"bytes32"}],"name":"RootUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"indexed":true,"internalType":"uint32","name":"domain","type":"uint32"},{"indexed":true,"internalType":"address","name":"agent","type":"address"}],"name":"StatusUpdated","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"agentRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"}],"name":"agentStatus","outputs":[{"components":[{"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"uint32","name":"index","type":"uint32"}],"internalType":"struct AgentStatus","name":"status","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cancelProposedAgentRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"destination","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"}],"name":"disputeStatus","outputs":[{"internalType":"enum DisputeFlag","name":"flag","type":"uint8"},{"internalType":"address","name":"rival","type":"address"},{"internalType":"address","name":"fraudProver","type":"address"},{"internalType":"uint256","name":"disputePtr","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getAgent","outputs":[{"internalType":"address","name":"agent","type":"address"},{"components":[{"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"uint32","name":"index","type":"uint32"}],"internalType":"struct AgentStatus","name":"status","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getDispute","outputs":[{"internalType":"address","name":"guard","type":"address"},{"internalType":"address","name":"notary","type":"address"},{"internalType":"address","name":"slashedAgent","type":"address"},{"internalType":"address","name":"fraudProver","type":"address"},{"internalType":"bytes","name":"reportPayload","type":"bytes"},{"internalType":"bytes","name":"reportSignature","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDisputesAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"inbox","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"origin_","type":"address"},{"internalType":"address","name":"destination_","type":"address"},{"internalType":"address","name":"inbox_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"localDomain","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"allowFailure","type":"bool"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct MultiCallable.Call[]","name":"calls","type":"tuple[]"}],"name":"multicall","outputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"}],"internalType":"struct MultiCallable.Result[]","name":"callResults","type":"tuple[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"guardIndex","type":"uint32"},{"internalType":"uint32","name":"notaryIndex","type":"uint32"}],"name":"openDispute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"origin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"agentRoot_","type":"bytes32"}],"name":"proposeAgentRootWhenStuck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proposedAgentRootData","outputs":[{"internalType":"bytes32","name":"agentRoot_","type":"bytes32"},{"internalType":"uint256","name":"proposedAt_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"msgOrigin","type":"uint32"},{"internalType":"uint256","name":"proofMaturity","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"remoteWithdrawTips","outputs":[{"internalType":"bytes4","name":"magicValue","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"resolveProposedAgentRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"agentRoot_","type":"bytes32"}],"name":"setAgentRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"address","name":"agent","type":"address"},{"internalType":"address","name":"prover","type":"address"}],"name":"slashAgent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"synapseDomain","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"},{"components":[{"internalType":"enum AgentFlag","name":"flag","type":"uint8"},{"internalType":"uint32","name":"domain","type":"uint32"},{"internalType":"uint32","name":"index","type":"uint32"}],"internalType":"struct AgentStatus","name":"status","type":"tuple"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"updateAgentStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"versionString","type":"string"}],"stateMutability":"view","type":"function"}],"userDoc":{"events":{"AgentRootProposed(bytes32)":{"notice":"Emitted after the contract owner proposes a new agent root to resolve the stuck chain."},"DisputeOpened(uint256,uint32,uint32)":{"notice":"Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits their report for the Notary-signed statement to `StatementInbox`."},"DisputeResolved(uint256,uint32,uint32,address)":{"notice":"Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed. Note: this won't be emitted, if an Agent was slashed without being in Dispute."},"ProposedAgentRootCancelled(bytes32)":{"notice":"Emitted after the contract owner cancels the previously proposed agent root."},"ProposedAgentRootResolved(bytes32)":{"notice":"Emitted after the contract owner resolves the previously proposed agent root."},"RootUpdated(bytes32)":{"notice":"Emitted whenever the root of the Agent Merkle Tree is updated."},"StatusUpdated(uint8,uint32,address)":{"notice":"Emitted whenever a status of the agent is updated."}},"kind":"user","methods":{"agentRoot()":{"notice":"Returns the latest known root of the Agent Merkle Tree."},"agentStatus(address)":{"notice":"Returns (flag, domain, index) for a given agent. See Structures.sol for details."},"cancelProposedAgentRoot()":{"notice":"Allows contract owner to cancel the previously proposed agent root."},"disputeStatus(address)":{"notice":"Returns the current Dispute status of a given agent. See Structures.sol for details."},"getAgent(uint256)":{"notice":"Returns agent address and their current status for a given agent index."},"getDispute(uint256)":{"notice":"Returns information about the dispute with the given index."},"getDisputesAmount()":{"notice":"Returns the number of opened Disputes."},"localDomain()":{"notice":"Domain of the local chain, set once upon contract creation"},"multicall((bool,bytes)[])":{"notice":"Aggregates a few calls to this contract into one multicall without modifying `msg.sender`."},"openDispute(uint32,uint32)":{"notice":"Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Guard or Notary is already in Dispute."},"proposeAgentRootWhenStuck(bytes32)":{"notice":"Allows contract owner to set the agent root to resolve the \"stuck\" chain by proposing the new agent root. The contract owner will be able to resolve the proposed agent root after a certain period of time. Note: this function could be called multiple times, each time the timer will be reset. This could only be called if no fresh data has been submitted by the Notaries to the Inbox, indicating that the chain is stuck for one of the reasons: - All active Notaries are in Dispute. - No active Notaries exist under the current agent root."},"proposedAgentRootData()":{"notice":"Returns the latest proposed agent root and the timestamp when it was proposed."},"remoteWithdrawTips(uint32,uint256,address,uint256)":{"notice":"Withdraws locked base message tips from local Origin to the recipient."},"resolveProposedAgentRoot()":{"notice":"Allows contract owner to resolve the previously proposed agent root. This will update the agent root, allowing the agents to update their status, effectively resolving the \"stuck\" chain."},"setAgentRoot(bytes32)":{"notice":"Updates the root of Agent Merkle Tree that the Light Manager is tracking. Could be only called by a local Destination contract, which is supposed to verify the attested Agent Merkle Roots."},"slashAgent(uint32,address,address)":{"notice":"Allows Inbox to slash an agent, if their fraud was proven. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Domain doesn't match the saved agent domain."},"updateAgentStatus(address,(uint8,uint32,uint32),bytes32[])":{"notice":"Updates agent status, using a proof against the latest known Agent Merkle Root."}},"notice":"LightManager keeps track of all agents on chains other than Synapse Chain. Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`. `LightManager` is responsible for the following: - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract. - Using these roots to enable agents to register themselves by proving their status. - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips. - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.","version":1},"developerDoc":{"kind":"dev","methods":{"acceptOwnership()":{"details":"The new owner accepts the ownership transfer."},"agentStatus(address)":{"details":"Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud, but their status is not updated to Slashed yet.","params":{"agent":"Agent address"},"returns":{"status":"Status for the given agent: (flag, domain, index)."}},"cancelProposedAgentRoot()":{"details":"Will revert if any of the following conditions is met: - Caller is not the contract owner. - No agent root was proposed."},"disputeStatus(address)":{"details":"Every returned value will be set to zero if agent was not slashed and is not in Dispute. `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.","params":{"agent":"Agent address"},"returns":{"disputePtr":"  Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.","flag":"        Flag describing the current Dispute status for the agent: None/Pending/Slashed","fraudProver":" Address who provided fraud proof to resolve the Dispute","rival":"       Address of the rival agent in the Dispute"}},"getAgent(uint256)":{"details":"Will return empty values if agent with given index doesn't exist.","params":{"index":"Agent index in the Agent Merkle Tree"},"returns":{"agent":"   Agent address","status":"  Status for the given agent: (flag, domain, index)"}},"getDispute(uint256)":{"details":"Will revert if dispute with given index hasn't been opened yet.","params":{"index":"Dispute index"},"returns":{"fraudProver":"     Address who provided fraud proof to resolve the Dispute","guard":"           Address of the Guard in the Dispute","notary":"          Address of the Notary in the Dispute","reportPayload":"   Raw payload with report data that led to the Dispute","reportSignature":" Guard signature for the report payload","slashedAgent":"    Address of the Agent who was slashed when Dispute was resolved"}},"getDisputesAmount()":{"details":"This includes the Disputes that have been resolved already."},"openDispute(uint32,uint32)":{"params":{"guardIndex":"Index of the Guard in the Agent Merkle Tree","notaryIndex":"Index of the Notary in the Agent Merkle Tree"}},"owner()":{"details":"Returns the address of the current owner."},"pendingOwner()":{"details":"Returns the address of the pending owner."},"proposeAgentRootWhenStuck(bytes32)":{"details":"Will revert if any of the following conditions is met: - Caller is not the contract owner. - Agent root is empty. - The chain is not in a stuck state (has recently received a fresh data from the Notaries).","params":{"agentRoot_":"New Agent Merkle Root that is proposed to be set"}},"proposedAgentRootData()":{"details":"Will return zero values if no agent root was proposed, or if the proposed agent root was already resolved."},"remoteWithdrawTips(uint32,uint256,address,uint256)":{"details":"Could only be remote-called by BondingManager contract on Synapse Chain. Note: as an extra security check this function returns its own selector, so that Destination could verify that a \"remote\" function was called when executing a manager message.","params":{"amount":"Tips value to withdraw","recipient":"Address to withdraw tips to"}},"renounceOwnership()":{"details":"Should be impossible to renounce ownership; we override OpenZeppelin OwnableUpgradeable's implementation of renounceOwnership to make it a no-op"},"resolveProposedAgentRoot()":{"details":"Should proceed with the proposed root, even if new Notary data is available. This is done to prevent rogue Notaries from going offline and then indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here."},"setAgentRoot(bytes32)":{"params":{"agentRoot_":"New Agent Merkle Root"}},"slashAgent(uint32,address,address)":{"params":{"agent":"Address of the Agent","domain":"Domain where the Agent is active","prover":"Address that initially provided fraud proof"}},"transferOwnership(address)":{"details":"Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner."},"updateAgentStatus(address,(uint8,uint32,uint32),bytes32[])":{"details":"Will revert if the provided proof doesn't match the latest merkle root.","params":{"agent":"Agent address","proof":"Merkle proof of Active status for the agent","status":"Structure specifying agent status: (flag, domain, index)"}}},"stateVariables":{"_agentRootProposedAt":{"details":"Timestamp when the Agent Merkle Root was proposed by the contract owner."},"_proposedAgentRoot":{"details":"Pending Agent Merkle Root that was proposed by the contract owner."}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"synapseDomain_\",\"type\":\"uint32\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"AgentNotActiveNorUnstaking\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AgentRootNotProposed\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"AgentRootTimeoutNotOver\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CallerNotDestination\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"CallerNotInbox\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"DisputeAlreadyResolved\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"GuardInDispute\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"IncorrectAgentDomain\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"IncorrectAgentIndex\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"IncorrectAgentProof\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"IncorrectAgentRoot\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"IncorrectVersionLength\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"IndexOutOfRange\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"MustBeSynapseDomain\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotStuck\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"NotaryInDispute\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"SynapseDomainForbidden\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"TreeHeightTooLow\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"WithdrawTipsOptimisticPeriod\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"newRoot\",\"type\":\"bytes32\"}],\"name\":\"AgentRootProposed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"disputeIndex\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"guardIndex\",\"type\":\"uint32\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"notaryIndex\",\"type\":\"uint32\"}],\"name\":\"DisputeOpened\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"disputeIndex\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"slashedIndex\",\"type\":\"uint32\"},{\"indexed\":false,\"internalType\":\"uint32\",\"name\":\"rivalIndex\",\"type\":\"uint32\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"fraudProver\",\"type\":\"address\"}],\"name\":\"DisputeResolved\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"version\",\"type\":\"uint8\"}],\"name\":\"Initialized\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferStarted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"proposedRoot\",\"type\":\"bytes32\"}],\"name\":\"ProposedAgentRootCancelled\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"proposedRoot\",\"type\":\"bytes32\"}],\"name\":\"ProposedAgentRootResolved\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"newRoot\",\"type\":\"bytes32\"}],\"name\":\"RootUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"indexed\":true,\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"StatusUpdated\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"acceptOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"agentRoot\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"agentStatus\",\"outputs\":[{\"components\":[{\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"index\",\"type\":\"uint32\"}],\"internalType\":\"struct AgentStatus\",\"name\":\"status\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"cancelProposedAgentRoot\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"destination\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"}],\"name\":\"disputeStatus\",\"outputs\":[{\"internalType\":\"enum DisputeFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"address\",\"name\":\"rival\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"fraudProver\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"disputePtr\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getAgent\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"index\",\"type\":\"uint32\"}],\"internalType\":\"struct AgentStatus\",\"name\":\"status\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getDispute\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"guard\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"notary\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"slashedAgent\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"fraudProver\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"reportPayload\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"reportSignature\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getDisputesAmount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"inbox\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"origin_\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"destination_\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"inbox_\",\"type\":\"address\"}],\"name\":\"initialize\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"localDomain\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bool\",\"name\":\"allowFailure\",\"type\":\"bool\"},{\"internalType\":\"bytes\",\"name\":\"callData\",\"type\":\"bytes\"}],\"internalType\":\"struct MultiCallable.Call[]\",\"name\":\"calls\",\"type\":\"tuple[]\"}],\"name\":\"multicall\",\"outputs\":[{\"components\":[{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"},{\"internalType\":\"bytes\",\"name\":\"returnData\",\"type\":\"bytes\"}],\"internalType\":\"struct MultiCallable.Result[]\",\"name\":\"callResults\",\"type\":\"tuple[]\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"guardIndex\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"notaryIndex\",\"type\":\"uint32\"}],\"name\":\"openDispute\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"origin\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pendingOwner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"agentRoot_\",\"type\":\"bytes32\"}],\"name\":\"proposeAgentRootWhenStuck\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"proposedAgentRootData\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"agentRoot_\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"proposedAt_\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"msgOrigin\",\"type\":\"uint32\"},{\"internalType\":\"uint256\",\"name\":\"proofMaturity\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"remoteWithdrawTips\",\"outputs\":[{\"internalType\":\"bytes4\",\"name\":\"magicValue\",\"type\":\"bytes4\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"resolveProposedAgentRoot\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"agentRoot_\",\"type\":\"bytes32\"}],\"name\":\"setAgentRoot\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"prover\",\"type\":\"address\"}],\"name\":\"slashAgent\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"synapseDomain\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"agent\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"enum AgentFlag\",\"name\":\"flag\",\"type\":\"uint8\"},{\"internalType\":\"uint32\",\"name\":\"domain\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"index\",\"type\":\"uint32\"}],\"internalType\":\"struct AgentStatus\",\"name\":\"status\",\"type\":\"tuple\"},{\"internalType\":\"bytes32[]\",\"name\":\"proof\",\"type\":\"bytes32[]\"}],\"name\":\"updateAgentStatus\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"versionString\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"acceptOwnership()\":{\"details\":\"The new owner accepts the ownership transfer.\"},\"agentStatus(address)\":{\"details\":\"Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud, but their status is not updated to Slashed yet.\",\"params\":{\"agent\":\"Agent address\"},\"returns\":{\"status\":\"Status for the given agent: (flag, domain, index).\"}},\"cancelProposedAgentRoot()\":{\"details\":\"Will revert if any of the following conditions is met: - Caller is not the contract owner. - No agent root was proposed.\"},\"disputeStatus(address)\":{\"details\":\"Every returned value will be set to zero if agent was not slashed and is not in Dispute. `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\",\"params\":{\"agent\":\"Agent address\"},\"returns\":{\"disputePtr\":\"  Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\",\"flag\":\"        Flag describing the current Dispute status for the agent: None/Pending/Slashed\",\"fraudProver\":\" Address who provided fraud proof to resolve the Dispute\",\"rival\":\"       Address of the rival agent in the Dispute\"}},\"getAgent(uint256)\":{\"details\":\"Will return empty values if agent with given index doesn't exist.\",\"params\":{\"index\":\"Agent index in the Agent Merkle Tree\"},\"returns\":{\"agent\":\"   Agent address\",\"status\":\"  Status for the given agent: (flag, domain, index)\"}},\"getDispute(uint256)\":{\"details\":\"Will revert if dispute with given index hasn't been opened yet.\",\"params\":{\"index\":\"Dispute index\"},\"returns\":{\"fraudProver\":\"     Address who provided fraud proof to resolve the Dispute\",\"guard\":\"           Address of the Guard in the Dispute\",\"notary\":\"          Address of the Notary in the Dispute\",\"reportPayload\":\"   Raw payload with report data that led to the Dispute\",\"reportSignature\":\" Guard signature for the report payload\",\"slashedAgent\":\"    Address of the Agent who was slashed when Dispute was resolved\"}},\"getDisputesAmount()\":{\"details\":\"This includes the Disputes that have been resolved already.\"},\"openDispute(uint32,uint32)\":{\"params\":{\"guardIndex\":\"Index of the Guard in the Agent Merkle Tree\",\"notaryIndex\":\"Index of the Notary in the Agent Merkle Tree\"}},\"owner()\":{\"details\":\"Returns the address of the current owner.\"},\"pendingOwner()\":{\"details\":\"Returns the address of the pending owner.\"},\"proposeAgentRootWhenStuck(bytes32)\":{\"details\":\"Will revert if any of the following conditions is met: - Caller is not the contract owner. - Agent root is empty. - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\",\"params\":{\"agentRoot_\":\"New Agent Merkle Root that is proposed to be set\"}},\"proposedAgentRootData()\":{\"details\":\"Will return zero values if no agent root was proposed, or if the proposed agent root was already resolved.\"},\"remoteWithdrawTips(uint32,uint256,address,uint256)\":{\"details\":\"Could only be remote-called by BondingManager contract on Synapse Chain. Note: as an extra security check this function returns its own selector, so that Destination could verify that a \\\"remote\\\" function was called when executing a manager message.\",\"params\":{\"amount\":\"Tips value to withdraw\",\"recipient\":\"Address to withdraw tips to\"}},\"renounceOwnership()\":{\"details\":\"Should be impossible to renounce ownership; we override OpenZeppelin OwnableUpgradeable's implementation of renounceOwnership to make it a no-op\"},\"resolveProposedAgentRoot()\":{\"details\":\"Should proceed with the proposed root, even if new Notary data is available. This is done to prevent rogue Notaries from going offline and then indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\"},\"setAgentRoot(bytes32)\":{\"params\":{\"agentRoot_\":\"New Agent Merkle Root\"}},\"slashAgent(uint32,address,address)\":{\"params\":{\"agent\":\"Address of the Agent\",\"domain\":\"Domain where the Agent is active\",\"prover\":\"Address that initially provided fraud proof\"}},\"transferOwnership(address)\":{\"details\":\"Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.\"},\"updateAgentStatus(address,(uint8,uint32,uint32),bytes32[])\":{\"details\":\"Will revert if the provided proof doesn't match the latest merkle root.\",\"params\":{\"agent\":\"Agent address\",\"proof\":\"Merkle proof of Active status for the agent\",\"status\":\"Structure specifying agent status: (flag, domain, index)\"}}},\"stateVariables\":{\"_agentRootProposedAt\":{\"details\":\"Timestamp when the Agent Merkle Root was proposed by the contract owner.\"},\"_proposedAgentRoot\":{\"details\":\"Pending Agent Merkle Root that was proposed by the contract owner.\"}},\"version\":1},\"userdoc\":{\"events\":{\"AgentRootProposed(bytes32)\":{\"notice\":\"Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\"},\"DisputeOpened(uint256,uint32,uint32)\":{\"notice\":\"Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits their report for the Notary-signed statement to `StatementInbox`.\"},\"DisputeResolved(uint256,uint32,uint32,address)\":{\"notice\":\"Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed. Note: this won't be emitted, if an Agent was slashed without being in Dispute.\"},\"ProposedAgentRootCancelled(bytes32)\":{\"notice\":\"Emitted after the contract owner cancels the previously proposed agent root.\"},\"ProposedAgentRootResolved(bytes32)\":{\"notice\":\"Emitted after the contract owner resolves the previously proposed agent root.\"},\"RootUpdated(bytes32)\":{\"notice\":\"Emitted whenever the root of the Agent Merkle Tree is updated.\"},\"StatusUpdated(uint8,uint32,address)\":{\"notice\":\"Emitted whenever a status of the agent is updated.\"}},\"kind\":\"user\",\"methods\":{\"agentRoot()\":{\"notice\":\"Returns the latest known root of the Agent Merkle Tree.\"},\"agentStatus(address)\":{\"notice\":\"Returns (flag, domain, index) for a given agent. See Structures.sol for details.\"},\"cancelProposedAgentRoot()\":{\"notice\":\"Allows contract owner to cancel the previously proposed agent root.\"},\"disputeStatus(address)\":{\"notice\":\"Returns the current Dispute status of a given agent. See Structures.sol for details.\"},\"getAgent(uint256)\":{\"notice\":\"Returns agent address and their current status for a given agent index.\"},\"getDispute(uint256)\":{\"notice\":\"Returns information about the dispute with the given index.\"},\"getDisputesAmount()\":{\"notice\":\"Returns the number of opened Disputes.\"},\"localDomain()\":{\"notice\":\"Domain of the local chain, set once upon contract creation\"},\"multicall((bool,bytes)[])\":{\"notice\":\"Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\"},\"openDispute(uint32,uint32)\":{\"notice\":\"Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Guard or Notary is already in Dispute.\"},\"proposeAgentRootWhenStuck(bytes32)\":{\"notice\":\"Allows contract owner to set the agent root to resolve the \\\"stuck\\\" chain by proposing the new agent root. The contract owner will be able to resolve the proposed agent root after a certain period of time. Note: this function could be called multiple times, each time the timer will be reset. This could only be called if no fresh data has been submitted by the Notaries to the Inbox, indicating that the chain is stuck for one of the reasons: - All active Notaries are in Dispute. - No active Notaries exist under the current agent root.\"},\"proposedAgentRootData()\":{\"notice\":\"Returns the latest proposed agent root and the timestamp when it was proposed.\"},\"remoteWithdrawTips(uint32,uint256,address,uint256)\":{\"notice\":\"Withdraws locked base message tips from local Origin to the recipient.\"},\"resolveProposedAgentRoot()\":{\"notice\":\"Allows contract owner to resolve the previously proposed agent root. This will update the agent root, allowing the agents to update their status, effectively resolving the \\\"stuck\\\" chain.\"},\"setAgentRoot(bytes32)\":{\"notice\":\"Updates the root of Agent Merkle Tree that the Light Manager is tracking. Could be only called by a local Destination contract, which is supposed to verify the attested Agent Merkle Roots.\"},\"slashAgent(uint32,address,address)\":{\"notice\":\"Allows Inbox to slash an agent, if their fraud was proven. \u003e Will revert if any of these is true: \u003e - Caller is not Inbox. \u003e - Domain doesn't match the saved agent domain.\"},\"updateAgentStatus(address,(uint8,uint32,uint32),bytes32[])\":{\"notice\":\"Updates agent status, using a proof against the latest known Agent Merkle Root.\"}},\"notice\":\"LightManager keeps track of all agents on chains other than Synapse Chain. Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`. `LightManager` is responsible for the following: - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract. - Using these roots to enable agents to register themselves by proving their status. - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips. - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"LightManager\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"acceptOwnership()":"79ba5097","agentRoot()":"36cba43c","agentStatus(address)":"28f3fac9","cancelProposedAgentRoot()":"91ea3c34","destination()":"b269681d","disputeStatus(address)":"3463d1b1","getAgent(uint256)":"2de5aaf7","getDispute(uint256)":"e3a96cbd","getDisputesAmount()":"3aaeccc6","inbox()":"fb0e722b","initialize(address,address,address)":"c0c53b8b","localDomain()":"8d3638f4","multicall((bool,bytes)[])":"60fc8466","openDispute(uint32,uint32)":"a2155c34","origin()":"938b5f32","owner()":"8da5cb5b","pendingOwner()":"e30c3978","proposeAgentRootWhenStuck(bytes32)":"dbad9562","proposedAgentRootData()":"5396feef","remoteWithdrawTips(uint32,uint256,address,uint256)":"1fa07138","renounceOwnership()":"715018a6","resolveProposedAgentRoot()":"38416281","setAgentRoot(bytes32)":"58668176","slashAgent(uint32,address,address)":"2853a0e6","synapseDomain()":"717b8638","transferOwnership(address)":"f2fde38b","updateAgentStatus(address,(uint8,uint32,uint32),bytes32[])":"cbd05965","version()":"54fd4d50"}},"solidity/LightManager.sol:MerkleMath":{"code":"0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212201072939e764d2eb95745d8b131d2784a3228649fe9899664a1e29edd16dd2c1064736f6c63430008110033","runtime-code":"0x73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212201072939e764d2eb95745d8b131d2784a3228649fe9899664a1e29edd16dd2c1064736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"94808:9845:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;94808:9845:0;;;;;;;;;;;;;;;;;","srcMapRuntime":"94808:9845:0:-:0;;;;;;;;","abiDefinition":[],"userDoc":{"kind":"user","methods":{},"version":1},"developerDoc":{"kind":"dev","methods":{},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"MerkleMath\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{}},"solidity/LightManager.sol:MessagingBase":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"inputs":[],"name":"IncorrectVersionLength","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"localDomain","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"allowFailure","type":"bool"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct MultiCallable.Call[]","name":"calls","type":"tuple[]"}],"name":"multicall","outputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"}],"internalType":"struct MultiCallable.Result[]","name":"callResults","type":"tuple[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"synapseDomain","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"versionString","type":"string"}],"stateMutability":"view","type":"function"}],"userDoc":{"kind":"user","methods":{"localDomain()":{"notice":"Domain of the local chain, set once upon contract creation"},"multicall((bool,bytes)[])":{"notice":"Aggregates a few calls to this contract into one multicall without modifying `msg.sender`."}},"notice":"Base contract for all messaging contracts. - Provides context on the local chain's domain. - Provides ownership functionality. - Will be providing pausing functionality when it is implemented.","version":1},"developerDoc":{"kind":"dev","methods":{"acceptOwnership()":{"details":"The new owner accepts the ownership transfer."},"owner()":{"details":"Returns the address of the current owner."},"pendingOwner()":{"details":"Returns the address of the pending owner."},"renounceOwnership()":{"details":"Should be impossible to renounce ownership; we override OpenZeppelin OwnableUpgradeable's implementation of renounceOwnership to make it a no-op"},"transferOwnership(address)":{"details":"Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner."}},"stateVariables":{"__GAP":{"details":"gap for upgrade safety"}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"IncorrectVersionLength\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"version\",\"type\":\"uint8\"}],\"name\":\"Initialized\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferStarted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"acceptOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"localDomain\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bool\",\"name\":\"allowFailure\",\"type\":\"bool\"},{\"internalType\":\"bytes\",\"name\":\"callData\",\"type\":\"bytes\"}],\"internalType\":\"struct MultiCallable.Call[]\",\"name\":\"calls\",\"type\":\"tuple[]\"}],\"name\":\"multicall\",\"outputs\":[{\"components\":[{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"},{\"internalType\":\"bytes\",\"name\":\"returnData\",\"type\":\"bytes\"}],\"internalType\":\"struct MultiCallable.Result[]\",\"name\":\"callResults\",\"type\":\"tuple[]\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pendingOwner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"synapseDomain\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"versionString\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"acceptOwnership()\":{\"details\":\"The new owner accepts the ownership transfer.\"},\"owner()\":{\"details\":\"Returns the address of the current owner.\"},\"pendingOwner()\":{\"details\":\"Returns the address of the pending owner.\"},\"renounceOwnership()\":{\"details\":\"Should be impossible to renounce ownership; we override OpenZeppelin OwnableUpgradeable's implementation of renounceOwnership to make it a no-op\"},\"transferOwnership(address)\":{\"details\":\"Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.\"}},\"stateVariables\":{\"__GAP\":{\"details\":\"gap for upgrade safety\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"localDomain()\":{\"notice\":\"Domain of the local chain, set once upon contract creation\"},\"multicall((bool,bytes)[])\":{\"notice\":\"Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\"}},\"notice\":\"Base contract for all messaging contracts. - Provides context on the local chain's domain. - Provides ownership functionality. - Will be providing pausing functionality when it is implemented.\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"MessagingBase\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"acceptOwnership()":"79ba5097","localDomain()":"8d3638f4","multicall((bool,bytes)[])":"60fc8466","owner()":"8da5cb5b","pendingOwner()":"e30c3978","renounceOwnership()":"715018a6","synapseDomain()":"717b8638","transferOwnership(address)":"f2fde38b","version()":"54fd4d50"}},"solidity/LightManager.sol:MultiCallable":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"inputs":[{"components":[{"internalType":"bool","name":"allowFailure","type":"bool"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct MultiCallable.Call[]","name":"calls","type":"tuple[]"}],"name":"multicall","outputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"}],"internalType":"struct MultiCallable.Result[]","name":"callResults","type":"tuple[]"}],"stateMutability":"nonpayable","type":"function"}],"userDoc":{"kind":"user","methods":{"multicall((bool,bytes)[])":{"notice":"Aggregates a few calls to this contract into one multicall without modifying `msg.sender`."}},"notice":"Collection of Multicall utilities. Fork of Multicall3: https://github.com/mds1/multicall/blob/master/src/Multicall3.sol","version":1},"developerDoc":{"kind":"dev","methods":{},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"components\":[{\"internalType\":\"bool\",\"name\":\"allowFailure\",\"type\":\"bool\"},{\"internalType\":\"bytes\",\"name\":\"callData\",\"type\":\"bytes\"}],\"internalType\":\"struct MultiCallable.Call[]\",\"name\":\"calls\",\"type\":\"tuple[]\"}],\"name\":\"multicall\",\"outputs\":[{\"components\":[{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"},{\"internalType\":\"bytes\",\"name\":\"returnData\",\"type\":\"bytes\"}],\"internalType\":\"struct MultiCallable.Result[]\",\"name\":\"callResults\",\"type\":\"tuple[]\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"multicall((bool,bytes)[])\":{\"notice\":\"Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\"}},\"notice\":\"Collection of Multicall utilities. Fork of Multicall3: https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"MultiCallable\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"multicall((bool,bytes)[])":"60fc8466"}},"solidity/LightManager.sol:NumberLib":{"code":"0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220ea65d36f277c7b46b540eedc7d446780c4965e7a48202cdab7dc27752e172c4e64736f6c63430008110033","runtime-code":"0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220ea65d36f277c7b46b540eedc7d446780c4965e7a48202cdab7dc27752e172c4e64736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"35875:4887:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;35875:4887:0;;;;;;;;;;;;;;;;;","srcMapRuntime":"35875:4887:0:-:0;;;;;;;;","abiDefinition":[],"userDoc":{"kind":"user","methods":{},"notice":"# Number Library for compact representation of uint256 numbers. - Number is stored using mantissa and exponent, each occupying 8 bits. - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`. - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent` \u003e - `0 \u003c= mantissa \u003c 256` \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256) # Number stack layout (from highest bits to lowest) | Position   | Field    | Type  | Bytes | | ---------- | -------- | ----- | ----- | | (002..001] | mantissa | uint8 | 1     | | (001..000] | exponent | uint8 | 1     |","version":1},"developerDoc":{"kind":"dev","methods":{},"stateVariables":{"BWAD_SHIFT":{"details":"We are using not using 10**18 as wad, because it is not stored precisely in NumberLib."},"SHIFT_MANTISSA":{"details":"Amount of bits to shift to mantissa field"}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"stateVariables\":{\"BWAD_SHIFT\":{\"details\":\"We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\"},\"SHIFT_MANTISSA\":{\"details\":\"Amount of bits to shift to mantissa field\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"notice\":\"# Number Library for compact representation of uint256 numbers. - Number is stored using mantissa and exponent, each occupying 8 bits. - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`. - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent` \u003e - `0 \u003c= mantissa \u003c 256` \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256) # Number stack layout (from highest bits to lowest) | Position   | Field    | Type  | Bytes | | ---------- | -------- | ----- | ----- | | (002..001] | mantissa | uint8 | 1     | | (001..000] | exponent | uint8 | 1     |\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"NumberLib\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{}},"solidity/LightManager.sol:Ownable2StepUpgradeable":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}],"userDoc":{"kind":"user","methods":{},"version":1},"developerDoc":{"details":"Contract module which provides access control mechanism, where there is an account (an owner) that can be granted exclusive access to specific functions. By default, the owner account will be the one that deploys the contract. This can later be changed with {transferOwnership} and {acceptOwnership}. This module is used through inheritance. It will make available all functions from parent (Ownable).","kind":"dev","methods":{"acceptOwnership()":{"details":"The new owner accepts the ownership transfer."},"owner()":{"details":"Returns the address of the current owner."},"pendingOwner()":{"details":"Returns the address of the pending owner."},"renounceOwnership()":{"details":"Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner."},"transferOwnership(address)":{"details":"Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner."}},"stateVariables":{"__gap":{"details":"This empty reserved space is put in place to allow future versions to add new variables without shifting down storage in the inheritance chain. See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps"}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"version\",\"type\":\"uint8\"}],\"name\":\"Initialized\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferStarted\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"acceptOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"pendingOwner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"details\":\"Contract module which provides access control mechanism, where there is an account (an owner) that can be granted exclusive access to specific functions. By default, the owner account will be the one that deploys the contract. This can later be changed with {transferOwnership} and {acceptOwnership}. This module is used through inheritance. It will make available all functions from parent (Ownable).\",\"kind\":\"dev\",\"methods\":{\"acceptOwnership()\":{\"details\":\"The new owner accepts the ownership transfer.\"},\"owner()\":{\"details\":\"Returns the address of the current owner.\"},\"pendingOwner()\":{\"details\":\"Returns the address of the pending owner.\"},\"renounceOwnership()\":{\"details\":\"Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.\"},\"transferOwnership(address)\":{\"details\":\"Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.\"}},\"stateVariables\":{\"__gap\":{\"details\":\"This empty reserved space is put in place to allow future versions to add new variables without shifting down storage in the inheritance chain. See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"Ownable2StepUpgradeable\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"acceptOwnership()":"79ba5097","owner()":"8da5cb5b","pendingOwner()":"e30c3978","renounceOwnership()":"715018a6","transferOwnership(address)":"f2fde38b"}},"solidity/LightManager.sol:OwnableUpgradeable":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}],"userDoc":{"kind":"user","methods":{},"version":1},"developerDoc":{"details":"Contract module which provides a basic access control mechanism, where there is an account (an owner) that can be granted exclusive access to specific functions. By default, the owner account will be the one that deploys the contract. This can later be changed with {transferOwnership}. This module is used through inheritance. It will make available the modifier `onlyOwner`, which can be applied to your functions to restrict their use to the owner.","kind":"dev","methods":{"owner()":{"details":"Returns the address of the current owner."},"renounceOwnership()":{"details":"Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner."},"transferOwnership(address)":{"details":"Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner."}},"stateVariables":{"__gap":{"details":"This empty reserved space is put in place to allow future versions to add new variables without shifting down storage in the inheritance chain. See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps"}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"version\",\"type\":\"uint8\"}],\"name\":\"Initialized\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"details\":\"Contract module which provides a basic access control mechanism, where there is an account (an owner) that can be granted exclusive access to specific functions. By default, the owner account will be the one that deploys the contract. This can later be changed with {transferOwnership}. This module is used through inheritance. It will make available the modifier `onlyOwner`, which can be applied to your functions to restrict their use to the owner.\",\"kind\":\"dev\",\"methods\":{\"owner()\":{\"details\":\"Returns the address of the current owner.\"},\"renounceOwnership()\":{\"details\":\"Leaves the contract without owner. It will not be possible to call `onlyOwner` functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.\"},\"transferOwnership(address)\":{\"details\":\"Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.\"}},\"stateVariables\":{\"__gap\":{\"details\":\"This empty reserved space is put in place to allow future versions to add new variables without shifting down storage in the inheritance chain. See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"OwnableUpgradeable\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"owner()":"8da5cb5b","renounceOwnership()":"715018a6","transferOwnership(address)":"f2fde38b"}},"solidity/LightManager.sol:SafeCast":{"code":"0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220033022d7c5e9690166545d0c4cab1ecd23863eccdd8f2a8e06913037ac06546664736f6c63430008110033","runtime-code":"0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220033022d7c5e9690166545d0c4cab1ecd23863eccdd8f2a8e06913037ac06546664736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"41699:34153:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;41699:34153:0;;;;;;;;;;;;;;;;;","srcMapRuntime":"41699:34153:0:-:0;;;;;;;;","abiDefinition":[],"userDoc":{"kind":"user","methods":{},"version":1},"developerDoc":{"details":"Wrappers over Solidity's uintXX/intXX casting operators with added overflow checks. Downcasting from uint256/int256 in Solidity does not revert on overflow. This can easily result in undesired exploitation or bugs, since developers usually assume that overflows raise errors. `SafeCast` restores this intuition by reverting the transaction when such an operation overflows. Using this library instead of the unchecked operations eliminates an entire class of bugs, so it's recommended to use it always. Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing all math on `uint256` and `int256` and then downcasting.","kind":"dev","methods":{},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"details\":\"Wrappers over Solidity's uintXX/intXX casting operators with added overflow checks. Downcasting from uint256/int256 in Solidity does not revert on overflow. This can easily result in undesired exploitation or bugs, since developers usually assume that overflows raise errors. `SafeCast` restores this intuition by reverting the transaction when such an operation overflows. Using this library instead of the unchecked operations eliminates an entire class of bugs, so it's recommended to use it always. Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing all math on `uint256` and `int256` and then downcasting.\",\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"SafeCast\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{}},"solidity/LightManager.sol:StructureUtils":{"code":"0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220b25b5e4c347a6d518a136951bc002d5f4ee33e4d480ab0cc0ae19937f06745a364736f6c63430008110033","runtime-code":"0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220b25b5e4c347a6d518a136951bc002d5f4ee33e4d480ab0cc0ae19937f06745a364736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"93567:1198:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;93567:1198:0;;;;;;;;;;;;;;;;;","srcMapRuntime":"93567:1198:0:-:0;;;;;;;;","abiDefinition":[],"userDoc":{"kind":"user","methods":{},"version":1},"developerDoc":{"kind":"dev","methods":{},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"StructureUtils\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{}},"solidity/LightManager.sol:Versioned":{"code":"0x","runtime-code":"0x","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17 ^0.8.0 ^0.8.1 ^0.8.2;\n\n// contracts/interfaces/IStatementInbox.sol\n\ninterface IStatementInbox {\n    // ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Notary.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param snapSignature     Notary signature for the Snapshot\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshot(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory snapSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,\n     * as well as Notary signature for the Attestation created from this Snapshot.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param srSignature       Guard signature for the report\n     * @param snapPayload       Raw payload with Snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithAttestation(\n        uint8 stateIndex,\n        bytes memory srSignature,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    /**\n     * @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,\n     * as well as Notary signature for the Attestation.\n     * \u003e StateReport is a Guard statement saying \"Reported state is invalid\".\n     * - This results in an opened Dispute between the Guard and the Notary.\n     * - Note: Guard could (but doesn't have to) form a StateReport and use other values from\n     * `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State index is out of range.\n     * \u003e - The Guard or the Notary are already in a Dispute\n     * @param stateIndex        Index of the reported State in the Snapshot\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @param snapProof         Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the Attestation\n     * @return wasAccepted      Whether the Report was accepted (resulting in Dispute between the agents)\n     */\n    function submitStateReportWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes memory srSignature,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool wasAccepted);\n\n    // ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════\n\n    /**\n     * @notice Verifies a message receipt signed by the Notary.\n     * - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).\n     * - Slashes the Notary, if the receipt is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt signer is not an active Notary.\n     * \u003e - Receipt's destination chain does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data\n     * @param rcptSignature     Notary signature for the receipt\n     * @return isValidReceipt   Whether the provided receipt is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)\n        external\n        returns (bool isValidReceipt);\n\n    /**\n     * @notice Verifies a Guard's receipt report signature.\n     * - Does nothing, if the report is valid (if the reported receipt is invalid).\n     * - Slashes the Guard, if the report is invalid (if the reported receipt is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - Receipt payload is not properly formatted.\n     * \u003e - Receipt Report signer is not an active Guard.\n     * \u003e - Receipt does not refer to this chain.\n     * @param rcptPayload       Raw payload with Receipt data that Guard reports as invalid\n     * @param rrSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)\n        external\n        returns (bool isValidReport);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithAttestation(\n        uint8 stateIndex,\n        bytes memory snapPayload,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Notary, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is not an active Notary.\n     * \u003e - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.\n     * \u003e - Snapshot Proof's first element does not match the State metadata.\n     * \u003e - Snapshot Proof length exceeds Snapshot Tree Height.\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        Index of state in the snapshot\n     * @param statePayload      Raw payload with State data to check\n     * @param snapProof         Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree\n     * @param attPayload        Raw payload with Attestation data\n     * @param attSignature      Notary signature for the attestation\n     * @return isValidState     Whether the provided state is valid.\n     *                          Notary is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshotProof(\n        uint8 stateIndex,\n        bytes memory statePayload,\n        bytes32[] memory snapProof,\n        bytes memory attPayload,\n        bytes memory attSignature\n    ) external returns (bool isValidState);\n\n    /**\n     * @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.\n     * - Does nothing, if the state is valid (matches the historical state of this contract).\n     * - Slashes the Agent, if the state is invalid.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Snapshot payload is not properly formatted.\n     * \u003e - Snapshot signer is not an active Agent.\n     * \u003e - State index is out of range.\n     * \u003e - State does not refer to this chain.\n     * @param stateIndex        State index to check\n     * @param snapPayload       Raw payload with snapshot data\n     * @param snapSignature     Agent signature for the snapshot\n     * @return isValidState     Whether the provided state is valid.\n     *                          Agent is slashed, if return value is FALSE.\n     */\n    function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)\n        external\n        returns (bool isValidState);\n\n    /**\n     * @notice Verifies a Guard's state report signature.\n     *  - Does nothing, if the report is valid (if the reported state is invalid).\n     *  - Slashes the Guard, if the report is invalid (if the reported state is valid).\n     * \u003e Will revert if any of these is true:\n     * \u003e - State payload is not properly formatted.\n     * \u003e - State Report signer is not an active Guard.\n     * \u003e - Reported State does not refer to this chain.\n     * @param statePayload      Raw payload with State data that Guard reports as invalid\n     * @param srSignature       Guard signature for the report\n     * @return isValidReport    Whether the provided report is valid.\n     *                          Guard is slashed, if return value is FALSE.\n     */\n    function verifyStateReport(bytes memory statePayload, bytes memory srSignature)\n        external\n        returns (bool isValidReport);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the amount of Guard Reports stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     */\n    function getReportsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns the Guard report with the given index stored in StatementInbox.\n     * \u003e Only reports that led to opening a Dispute are stored.\n     * @dev Will revert if report with given index doesn't exist.\n     * @param index             Report index\n     * @return statementPayload Raw payload with statement that Guard reported as invalid\n     * @return reportSignature  Guard signature for the report\n     */\n    function getGuardReport(uint256 index)\n        external\n        view\n        returns (bytes memory statementPayload, bytes memory reportSignature);\n\n    /**\n     * @notice Returns the signature with the given index stored in StatementInbox.\n     * @dev Will revert if signature with given index doesn't exist.\n     * @param index     Signature index\n     * @return          Raw payload with signature\n     */\n    function getStoredSignature(uint256 index) external view returns (bytes memory);\n}\n\n// contracts/interfaces/InterfaceBondingManager.sol\n\ninterface InterfaceBondingManager {\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /**\n     * @notice Adds a new agent for the domain. This is either a fresh address (Inactive),\n     * or an agent who used to be active on the same domain before (Resting).\n     * @dev Inactive: `proof` should be the proof of inclusion of an empty leaf\n     * having index following the last added agent in the tree.\n     * @dev Resting: `proof` should be the proof of inclusion of the agent leaf\n     * with Resting flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent will be active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Inactive/Resting status for the agent\n     */\n    function addAgent(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Initiates the unstaking of the agent bond. Agent signature is immediately no longer\n     * considered valid on Synapse Chain, and will be invalid on other chains once the Light Manager\n     * updates their agent merkle root on these chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the Active status for the agent\n     */\n    function initiateUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the unstaking of the agent bond. Agent signature is no longer considered\n     * valid on any of the chains.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the unstaking status for the agent\n     */\n    function completeUnstaking(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Completes the slashing of the agent bond. Agent signature is no longer considered\n     * valid under the updated Agent Merkle Root.\n     * @dev `proof` should be the proof of inclusion of the agent leaf\n     * with Active/Unstaking flag having index previously assigned to the agent.\n     * @param domain    Domain where the Agent was active\n     * @param agent     Address of the Agent\n     * @param proof     Merkle proof of the active/unstaking status for the agent\n     */\n    function completeSlashing(uint32 domain, address agent, bytes32[] memory proof) external;\n\n    /**\n     * @notice Remote AgentManager should call this function to indicate that the agent\n     * has been proven to commit fraud on the origin chain.\n     * @dev This initiates the process of agent slashing. It could be immediately\n     * completed by anyone calling completeSlashing() providing a correct merkle proof\n     * for the OLD agent status.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * Will revert if `msgOrigin` is equal to contract's local domain.\n     * @param domain        Domain where the slashed agent was active\n     * @param agent         Address of the slashed Agent\n     * @param prover        Address that initially provided fraud proof to remote AgentManager\n     * @return magicValue   Selector of this function\n     */\n    function remoteSlashAgent(uint32 msgOrigin, uint256 proofMaturity, uint32 domain, address agent, address prover)\n        external\n        returns (bytes4 magicValue);\n\n    /**\n     * @notice Withdraws locked base message tips from requested domain Origin to the recipient.\n     * Issues a call to a local Origin contract, or sends a manager message to the remote chain.\n     * @dev Could only be called by the Summit contract.\n     * @param recipient     Address to withdraw tips to\n     * @param origin        Domain where tips need to be withdrawn\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint32 origin, uint256 amount) external;\n\n    /**\n     * @notice Allows contract owner to resolve a stuck Dispute.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * which is required for the Dispute to be resolved naturally.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not contract owner.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * \u003e - `slashedAgent` is not in Dispute.\n     * \u003e - Less than `FRESH_DATA_TIMEOUT` has passed since the last Notary submission to the Inbox.\n     * @param slashedAgent  Agent that is being slashed\n     */\n    function resolveDisputeWhenStuck(uint32 domain, address slashedAgent) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns all active agents for a given domain.\n     * @param domain    Domain to get agents from (ZERO for Guards)\n     * @param agents    List of active agents for the domain\n     */\n    function getActiveAgents(uint32 domain) external view returns (address[] memory agents);\n\n    /**\n     * @notice Returns a leaf representing the current status of agent in the Agent Merkle Tree.\n     * @dev Will return an empty leaf, if agent is not added to the tree yet.\n     * @param agent     Agent address\n     * @return leaf     Agent leaf in the Agent Merkle Tree\n     */\n    function agentLeaf(address agent) external view returns (bytes32 leaf);\n\n    /**\n     * @notice Returns a total amount of leafs representing known agents.\n     * @dev This includes active, unstaking, resting and slashed agents.\n     * This also includes an empty leaf as the very first entry.\n     */\n    function leafsAmount() external view returns (uint256 amount);\n\n    /**\n     * @notice Returns a full list of leafs from the Agent Merkle Tree.\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     */\n    function allLeafs() external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a list of leafs from the Agent Merkle Tree\n     * with indexes [indexFrom .. indexFrom + amount).\n     * @dev This might consume a lot of gas, do not use this on-chain.\n     * @dev Will return less than `amount` entries, if indexFrom + amount \u003e leafsAmount\n     */\n    function getLeafs(uint256 indexFrom, uint256 amount) external view returns (bytes32[] memory leafs);\n\n    /**\n     * @notice Returns a proof of inclusion of the agent in the Agent Merkle Tree.\n     * @dev Will return a proof for an empty leaf, if agent is not added to the tree yet.\n     * This proof could be used by ANY next new agent that calls {addAgent}.\n     * @dev This WILL consume a lot of gas, do not use this on-chain.\n     * @dev The alternative way to create a proof is to fetch the full list of leafs using\n     * either {allLeafs} or {getLeafs}, and create a merkle proof from that.\n     * @param agent     Agent address\n     * @return proof    Merkle proof for the agent\n     */\n    function getProof(address agent) external view returns (bytes32[] memory proof);\n}\n\n// contracts/interfaces/InterfaceOrigin.sol\n\ninterface InterfaceOrigin {\n    // ═══════════════════════════════════════════════ SEND MESSAGES ═══════════════════════════════════════════════════\n\n    /**\n     * @notice Send a message to the recipient located on destination domain.\n     * @dev Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered.\n     * Will revert if any of these is true:\n     * - `destination` is equal to contract's local domain\n     * - `content` length is greater than `MAX_CONTENT_BYTES`\n     * - `msg.value` is lower than value of minimum tips for the given message\n     * @param destination           Domain of destination chain\n     * @param recipient             Address of recipient on destination chain as bytes32\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param paddedRequest         Padded encoded message execution request on destination chain\n     * @param content               Raw bytes content of message\n     * @return messageNonce         Nonce of the sent message\n     * @return messageHash          Hash of the sent message\n     */\n    function sendBaseMessage(\n        uint32 destination,\n        bytes32 recipient,\n        uint32 optimisticPeriod,\n        uint256 paddedRequest,\n        bytes memory content\n    ) external payable returns (uint32 messageNonce, bytes32 messageHash);\n\n    /**\n     * @notice Send a manager message to the destination domain.\n     * @dev This could only be called by AgentManager, which takes care of encoding the calldata payload.\n     * Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain\n     * so that the AgentManager could verify where the Manager Message came from and how mature is the proof.\n     * Note: function is not payable, as no tips are required for sending a manager message.\n     * Will revert if `destination` is equal to contract's local domain.\n     * @param destination           Domain of destination chain\n     * @param optimisticPeriod      Optimistic period for message execution on destination chain\n     * @param payload               Payload for calling AgentManager on destination chain (with extra security args)\n     */\n    function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)\n        external\n        returns (uint32 messageNonce, bytes32 messageHash);\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /**\n     * @notice Withdraws locked base message tips to the recipient.\n     * @dev Could only be called by a local AgentManager.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function withdrawTips(address recipient, uint256 amount) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the minimum tips value for sending a message to a given destination.\n     * @dev Using at least `tipsValue` as `msg.value` for `sendBaseMessage()`\n     * will guarantee that the message will be accepted.\n     * @param destination       Domain of destination chain\n     * @param paddedRequest     Padded encoded message execution request on destination chain\n     * @param contentLength     The length of the message content\n     * @return tipsValue        Minimum tips value for a message to be accepted\n     */\n    function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)\n        external\n        view\n        returns (uint256 tipsValue);\n}\n\n// contracts/libs/Constants.sol\n\n// Here we define common constants to enable their easier reusing later.\n\n// ══════════════════════════════════ MERKLE ═══════════════════════════════════\n/// @dev Height of the Agent Merkle Tree\nuint256 constant AGENT_TREE_HEIGHT = 32;\n/// @dev Height of the Origin Merkle Tree\nuint256 constant ORIGIN_TREE_HEIGHT = 32;\n/// @dev Height of the Snapshot Merkle Tree. Allows up to 64 leafs, e.g. up to 32 states\nuint256 constant SNAPSHOT_TREE_HEIGHT = 6;\n// ══════════════════════════════════ STRUCTS ══════════════════════════════════\n/// @dev See Attestation.sol: (bytes32,bytes32,uint32,uint40,uint40): 32+32+4+5+5\nuint256 constant ATTESTATION_LENGTH = 78;\n/// @dev See GasData.sol: (uint16,uint16,uint16,uint16,uint16,uint16): 2+2+2+2+2+2\nuint256 constant GAS_DATA_LENGTH = 12;\n/// @dev See Receipt.sol: (uint32,uint32,bytes32,bytes32,uint8,address,address,address): 4+4+32+32+1+20+20+20\nuint256 constant RECEIPT_LENGTH = 133;\n/// @dev See State.sol: (bytes32,uint32,uint32,uint40,uint40,GasData): 32+4+4+5+5+len(GasData)\nuint256 constant STATE_LENGTH = 50 + GAS_DATA_LENGTH;\n/// @dev Maximum amount of states in a single snapshot. Each state produces two leafs in the tree\nuint256 constant SNAPSHOT_MAX_STATES = 1 \u003c\u003c (SNAPSHOT_TREE_HEIGHT - 1);\n// ══════════════════════════════════ MESSAGE ══════════════════════════════════\n/// @dev See Header.sol: (uint8,uint32,uint32,uint32,uint32): 1+4+4+4+4\nuint256 constant HEADER_LENGTH = 17;\n/// @dev See Request.sol: (uint96,uint64,uint32): 12+8+4\nuint256 constant REQUEST_LENGTH = 24;\n/// @dev See Tips.sol: (uint64,uint64,uint64,uint64): 8+8+8+8\nuint256 constant TIPS_LENGTH = 32;\n/// @dev The amount of discarded last bits when encoding tip values\nuint256 constant TIPS_GRANULARITY = 32;\n/// @dev Tip values could be only the multiples of TIPS_MULTIPLIER\nuint256 constant TIPS_MULTIPLIER = 1 \u003c\u003c TIPS_GRANULARITY;\n// ══════════════════════════════ STATEMENT SALTS ══════════════════════════════\n/// @dev Salts for signing various statements\nbytes32 constant ATTESTATION_VALID_SALT = keccak256(\"ATTESTATION_VALID_SALT\");\nbytes32 constant ATTESTATION_INVALID_SALT = keccak256(\"ATTESTATION_INVALID_SALT\");\nbytes32 constant RECEIPT_VALID_SALT = keccak256(\"RECEIPT_VALID_SALT\");\nbytes32 constant RECEIPT_INVALID_SALT = keccak256(\"RECEIPT_INVALID_SALT\");\nbytes32 constant SNAPSHOT_VALID_SALT = keccak256(\"SNAPSHOT_VALID_SALT\");\nbytes32 constant STATE_INVALID_SALT = keccak256(\"STATE_INVALID_SALT\");\n// ═════════════════════════════════ PROTOCOL ══════════════════════════════════\n/// @dev Optimistic period for new agent roots in LightManager\nuint32 constant AGENT_ROOT_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Timeout between the agent root could be proposed and resolved in LightManager\nuint32 constant AGENT_ROOT_PROPOSAL_TIMEOUT = 12 hours;\nuint32 constant BONDING_OPTIMISTIC_PERIOD = 1 days;\n/// @dev Amount of time that the Notary will not be considered active after they won a dispute\nuint32 constant DISPUTE_TIMEOUT_NOTARY = 12 hours;\n/// @dev Amount of time without fresh data from Notaries before contract owner can resolve stuck disputes manually\nuint256 constant FRESH_DATA_TIMEOUT = 4 hours;\n/// @dev Maximum bytes per message = 2 KiB (somewhat arbitrarily set to begin)\nuint256 constant MAX_CONTENT_BYTES = 2 * 2 ** 10;\n/// @dev Maximum value for the summit tip that could be set in GasOracle\nuint256 constant MAX_SUMMIT_TIP = 0.01 ether;\n\n// contracts/libs/Errors.sol\n\n// ══════════════════════════════ INVALID CALLER ═══════════════════════════════\n\nerror CallerNotAgentManager();\nerror CallerNotDestination();\nerror CallerNotInbox();\nerror CallerNotSummit();\n\n// ══════════════════════════════ INCORRECT DATA ═══════════════════════════════\n\nerror IncorrectAttestation();\nerror IncorrectAgentDomain();\nerror IncorrectAgentIndex();\nerror IncorrectAgentProof();\nerror IncorrectAgentRoot();\nerror IncorrectDataHash();\nerror IncorrectDestinationDomain();\nerror IncorrectOriginDomain();\nerror IncorrectSnapshotProof();\nerror IncorrectSnapshotRoot();\nerror IncorrectState();\nerror IncorrectStatesAmount();\nerror IncorrectTipsProof();\nerror IncorrectVersionLength();\n\nerror IncorrectNonce();\nerror IncorrectSender();\nerror IncorrectRecipient();\n\nerror FlagOutOfRange();\nerror IndexOutOfRange();\nerror NonceOutOfRange();\n\nerror OutdatedNonce();\n\nerror UnformattedAttestation();\nerror UnformattedAttestationReport();\nerror UnformattedBaseMessage();\nerror UnformattedCallData();\nerror UnformattedCallDataPrefix();\nerror UnformattedMessage();\nerror UnformattedReceipt();\nerror UnformattedReceiptReport();\nerror UnformattedSignature();\nerror UnformattedSnapshot();\nerror UnformattedState();\nerror UnformattedStateReport();\n\n// ═══════════════════════════════ MERKLE TREES ════════════════════════════════\n\nerror LeafNotProven();\nerror MerkleTreeFull();\nerror NotEnoughLeafs();\nerror TreeHeightTooLow();\n\n// ═════════════════════════════ OPTIMISTIC PERIOD ═════════════════════════════\n\nerror BaseClientOptimisticPeriod();\nerror MessageOptimisticPeriod();\nerror SlashAgentOptimisticPeriod();\nerror WithdrawTipsOptimisticPeriod();\nerror ZeroProofMaturity();\n\n// ═══════════════════════════════ AGENT MANAGER ═══════════════════════════════\n\nerror AgentNotGuard();\nerror AgentNotNotary();\n\nerror AgentCantBeAdded();\nerror AgentNotActive();\nerror AgentNotActiveNorUnstaking();\nerror AgentNotFraudulent();\nerror AgentNotUnstaking();\nerror AgentUnknown();\n\nerror AgentRootNotProposed();\nerror AgentRootTimeoutNotOver();\n\nerror NotStuck();\n\nerror DisputeAlreadyResolved();\nerror DisputeNotOpened();\nerror DisputeTimeoutNotOver();\nerror GuardInDispute();\nerror NotaryInDispute();\n\nerror MustBeSynapseDomain();\nerror SynapseDomainForbidden();\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\nerror AlreadyExecuted();\nerror AlreadyFailed();\nerror DuplicatedSnapshotRoot();\nerror IncorrectMagicValue();\nerror GasLimitTooLow();\nerror GasSuppliedTooLow();\n\n// ══════════════════════════════════ ORIGIN ═══════════════════════════════════\n\nerror ContentLengthTooBig();\nerror EthTransferFailed();\nerror InsufficientEthBalance();\n\n// ════════════════════════════════ GAS ORACLE ═════════════════════════════════\n\nerror LocalGasDataNotSet();\nerror RemoteGasDataNotSet();\n\n// ═══════════════════════════════════ TIPS ════════════════════════════════════\n\nerror SummitTipTooHigh();\nerror TipsClaimMoreThanEarned();\nerror TipsClaimZero();\nerror TipsOverflow();\nerror TipsValueTooLow();\n\n// ════════════════════════════════ MEMORY VIEW ════════════════════════════════\n\nerror IndexedTooMuch();\nerror ViewOverrun();\nerror OccupiedMemory();\nerror UnallocatedMemory();\nerror PrecompileOutOfGas();\n\n// ═════════════════════════════════ MULTICALL ═════════════════════════════════\n\nerror MulticallFailed();\n\n// contracts/libs/stack/Number.sol\n\n/// Number is a compact representation of uint256, that is fit into 16 bits\n/// with the maximum relative error under 0.4%.\ntype Number is uint16;\n\nusing NumberLib for Number global;\n\n/// # Number\n/// Library for compact representation of uint256 numbers.\n/// - Number is stored using mantissa and exponent, each occupying 8 bits.\n/// - Numbers under 2**8 are stored as `mantissa` with `exponent = 0xFF`.\n/// - Numbers at least 2**8 are approximated as `(256 + mantissa) \u003c\u003c exponent`\n/// \u003e - `0 \u003c= mantissa \u003c 256`\n/// \u003e - `0 \u003c= exponent \u003c= 247` (`256 * 2**248` doesn't fit into uint256)\n/// # Number stack layout (from highest bits to lowest)\n///\n/// | Position   | Field    | Type  | Bytes |\n/// | ---------- | -------- | ----- | ----- |\n/// | (002..001] | mantissa | uint8 | 1     |\n/// | (001..000] | exponent | uint8 | 1     |\n\nlibrary NumberLib {\n    /// @dev Amount of bits to shift to mantissa field\n    uint16 private constant SHIFT_MANTISSA = 8;\n\n    /// @notice For bwad math (binary wad) we use 2**64 as \"wad\" unit.\n    /// @dev We are using not using 10**18 as wad, because it is not stored precisely in NumberLib.\n    uint256 internal constant BWAD_SHIFT = 64;\n    uint256 internal constant BWAD = 1 \u003c\u003c BWAD_SHIFT;\n    /// @notice ~0.1% in bwad units.\n    uint256 internal constant PER_MILLE_SHIFT = BWAD_SHIFT - 10;\n    uint256 internal constant PER_MILLE = 1 \u003c\u003c PER_MILLE_SHIFT;\n\n    /// @notice Compresses uint256 number into 16 bits.\n    function compress(uint256 value) internal pure returns (Number) {\n        // Find `msb` such as `2**msb \u003c= value \u003c 2**(msb + 1)`\n        uint256 msb = mostSignificantBit(value);\n        // We want to preserve 9 bits of precision.\n        // The highest bit is always 1, so we can skip it.\n        // The remaining 8 highest bits are stored as mantissa.\n        if (msb \u003c 8) {\n            // Value is less than 2**8, so we can use value as mantissa with \"-1\" exponent.\n            return _encode(uint8(value), 0xFF);\n        } else {\n            // We use `msb - 8` as exponent otherwise. Note that `exponent \u003e= 0`.\n            unchecked {\n                uint256 exponent = msb - 8;\n                // Shifting right by `msb-8` bits will shift the \"remaining 8 highest bits\" into the 8 lowest bits.\n                // uint8() will truncate the highest bit.\n                return _encode(uint8(value \u003e\u003e exponent), uint8(exponent));\n            }\n        }\n    }\n\n    /// @notice Decompresses 16 bits number into uint256.\n    /// @dev The outcome is an approximation of the original number: `(value - value / 256) \u003c number \u003c= value`.\n    function decompress(Number number) internal pure returns (uint256 value) {\n        // Isolate 8 highest bits as the mantissa.\n        uint256 mantissa = Number.unwrap(number) \u003e\u003e SHIFT_MANTISSA;\n        // This will truncate the highest bits, leaving only the exponent.\n        uint256 exponent = uint8(Number.unwrap(number));\n        if (exponent == 0xFF) {\n            return mantissa;\n        } else {\n            unchecked {\n                return (256 + mantissa) \u003c\u003c (exponent);\n            }\n        }\n    }\n\n    /// @dev Returns the most significant bit of `x`\n    /// https://solidity-by-example.org/bitwise/\n    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {\n        // To find `msb` we determine it bit by bit, starting from the highest one.\n        // `0 \u003c= msb \u003c= 255`, so we start from the highest bit, 1\u003c\u003c7 == 128.\n        // If `x` is at least 2**128, then the highest bit of `x` is at least 128.\n        // solhint-disable no-inline-assembly\n        assembly {\n            // `f` is set to 1\u003c\u003c7 if `x \u003e= 2**128` and to 0 otherwise.\n            let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            // If `x \u003e= 2**128` then set `msb` highest bit to 1 and shift `x` right by 128.\n            // Otherwise, `msb` remains 0 and `x` remains unchanged.\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        // `x` is now at most 2**128 - 1. Continue the same way, the next highest bit is 1\u003c\u003c6 == 64.\n        assembly {\n            // `f` is set to 1\u003c\u003c6 if `x \u003e= 2**64` and to 0 otherwise.\n            let f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c5 if `x \u003e= 2**32` and to 0 otherwise.\n            let f := shl(5, gt(x, 0xFFFFFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c4 if `x \u003e= 2**16` and to 0 otherwise.\n            let f := shl(4, gt(x, 0xFFFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c3 if `x \u003e= 2**8` and to 0 otherwise.\n            let f := shl(3, gt(x, 0xFF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c2 if `x \u003e= 2**4` and to 0 otherwise.\n            let f := shl(2, gt(x, 0xF))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1\u003c\u003c1 if `x \u003e= 2**2` and to 0 otherwise.\n            let f := shl(1, gt(x, 0x3))\n            x := shr(f, x)\n            msb := or(msb, f)\n        }\n        assembly {\n            // `f` is set to 1 if `x \u003e= 2**1` and to 0 otherwise.\n            let f := gt(x, 0x1)\n            msb := or(msb, f)\n        }\n    }\n\n    /// @dev Wraps (mantissa, exponent) pair into Number.\n    function _encode(uint8 mantissa, uint8 exponent) private pure returns (Number) {\n        // Casts below are upcasts, so they are safe.\n        return Number.wrap(uint16(mantissa) \u003c\u003c SHIFT_MANTISSA | uint16(exponent));\n    }\n}\n\n// node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol\n\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n    /**\n     * @dev Returns the downcasted uint248 from uint256, reverting on\n     * overflow (when the input is greater than largest uint248).\n     *\n     * Counterpart to Solidity's `uint248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint248(uint256 value) internal pure returns (uint248) {\n        require(value \u003c= type(uint248).max, \"SafeCast: value doesn't fit in 248 bits\");\n        return uint248(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint240 from uint256, reverting on\n     * overflow (when the input is greater than largest uint240).\n     *\n     * Counterpart to Solidity's `uint240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint240(uint256 value) internal pure returns (uint240) {\n        require(value \u003c= type(uint240).max, \"SafeCast: value doesn't fit in 240 bits\");\n        return uint240(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint232 from uint256, reverting on\n     * overflow (when the input is greater than largest uint232).\n     *\n     * Counterpart to Solidity's `uint232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint232(uint256 value) internal pure returns (uint232) {\n        require(value \u003c= type(uint232).max, \"SafeCast: value doesn't fit in 232 bits\");\n        return uint232(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint224 from uint256, reverting on\n     * overflow (when the input is greater than largest uint224).\n     *\n     * Counterpart to Solidity's `uint224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint224(uint256 value) internal pure returns (uint224) {\n        require(value \u003c= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n        return uint224(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint216 from uint256, reverting on\n     * overflow (when the input is greater than largest uint216).\n     *\n     * Counterpart to Solidity's `uint216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint216(uint256 value) internal pure returns (uint216) {\n        require(value \u003c= type(uint216).max, \"SafeCast: value doesn't fit in 216 bits\");\n        return uint216(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint208 from uint256, reverting on\n     * overflow (when the input is greater than largest uint208).\n     *\n     * Counterpart to Solidity's `uint208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint208(uint256 value) internal pure returns (uint208) {\n        require(value \u003c= type(uint208).max, \"SafeCast: value doesn't fit in 208 bits\");\n        return uint208(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint200 from uint256, reverting on\n     * overflow (when the input is greater than largest uint200).\n     *\n     * Counterpart to Solidity's `uint200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint200(uint256 value) internal pure returns (uint200) {\n        require(value \u003c= type(uint200).max, \"SafeCast: value doesn't fit in 200 bits\");\n        return uint200(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint192 from uint256, reverting on\n     * overflow (when the input is greater than largest uint192).\n     *\n     * Counterpart to Solidity's `uint192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint192(uint256 value) internal pure returns (uint192) {\n        require(value \u003c= type(uint192).max, \"SafeCast: value doesn't fit in 192 bits\");\n        return uint192(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint184 from uint256, reverting on\n     * overflow (when the input is greater than largest uint184).\n     *\n     * Counterpart to Solidity's `uint184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint184(uint256 value) internal pure returns (uint184) {\n        require(value \u003c= type(uint184).max, \"SafeCast: value doesn't fit in 184 bits\");\n        return uint184(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint176 from uint256, reverting on\n     * overflow (when the input is greater than largest uint176).\n     *\n     * Counterpart to Solidity's `uint176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint176(uint256 value) internal pure returns (uint176) {\n        require(value \u003c= type(uint176).max, \"SafeCast: value doesn't fit in 176 bits\");\n        return uint176(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint168 from uint256, reverting on\n     * overflow (when the input is greater than largest uint168).\n     *\n     * Counterpart to Solidity's `uint168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint168(uint256 value) internal pure returns (uint168) {\n        require(value \u003c= type(uint168).max, \"SafeCast: value doesn't fit in 168 bits\");\n        return uint168(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint160 from uint256, reverting on\n     * overflow (when the input is greater than largest uint160).\n     *\n     * Counterpart to Solidity's `uint160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint160(uint256 value) internal pure returns (uint160) {\n        require(value \u003c= type(uint160).max, \"SafeCast: value doesn't fit in 160 bits\");\n        return uint160(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint152 from uint256, reverting on\n     * overflow (when the input is greater than largest uint152).\n     *\n     * Counterpart to Solidity's `uint152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint152(uint256 value) internal pure returns (uint152) {\n        require(value \u003c= type(uint152).max, \"SafeCast: value doesn't fit in 152 bits\");\n        return uint152(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint144 from uint256, reverting on\n     * overflow (when the input is greater than largest uint144).\n     *\n     * Counterpart to Solidity's `uint144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint144(uint256 value) internal pure returns (uint144) {\n        require(value \u003c= type(uint144).max, \"SafeCast: value doesn't fit in 144 bits\");\n        return uint144(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint136 from uint256, reverting on\n     * overflow (when the input is greater than largest uint136).\n     *\n     * Counterpart to Solidity's `uint136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint136(uint256 value) internal pure returns (uint136) {\n        require(value \u003c= type(uint136).max, \"SafeCast: value doesn't fit in 136 bits\");\n        return uint136(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint128 from uint256, reverting on\n     * overflow (when the input is greater than largest uint128).\n     *\n     * Counterpart to Solidity's `uint128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint128(uint256 value) internal pure returns (uint128) {\n        require(value \u003c= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n        return uint128(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint120 from uint256, reverting on\n     * overflow (when the input is greater than largest uint120).\n     *\n     * Counterpart to Solidity's `uint120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint120(uint256 value) internal pure returns (uint120) {\n        require(value \u003c= type(uint120).max, \"SafeCast: value doesn't fit in 120 bits\");\n        return uint120(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint112 from uint256, reverting on\n     * overflow (when the input is greater than largest uint112).\n     *\n     * Counterpart to Solidity's `uint112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint112(uint256 value) internal pure returns (uint112) {\n        require(value \u003c= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n        return uint112(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint104 from uint256, reverting on\n     * overflow (when the input is greater than largest uint104).\n     *\n     * Counterpart to Solidity's `uint104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint104(uint256 value) internal pure returns (uint104) {\n        require(value \u003c= type(uint104).max, \"SafeCast: value doesn't fit in 104 bits\");\n        return uint104(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint96 from uint256, reverting on\n     * overflow (when the input is greater than largest uint96).\n     *\n     * Counterpart to Solidity's `uint96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.2._\n     */\n    function toUint96(uint256 value) internal pure returns (uint96) {\n        require(value \u003c= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n        return uint96(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint88 from uint256, reverting on\n     * overflow (when the input is greater than largest uint88).\n     *\n     * Counterpart to Solidity's `uint88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint88(uint256 value) internal pure returns (uint88) {\n        require(value \u003c= type(uint88).max, \"SafeCast: value doesn't fit in 88 bits\");\n        return uint88(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint80 from uint256, reverting on\n     * overflow (when the input is greater than largest uint80).\n     *\n     * Counterpart to Solidity's `uint80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint80(uint256 value) internal pure returns (uint80) {\n        require(value \u003c= type(uint80).max, \"SafeCast: value doesn't fit in 80 bits\");\n        return uint80(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint72 from uint256, reverting on\n     * overflow (when the input is greater than largest uint72).\n     *\n     * Counterpart to Solidity's `uint72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint72(uint256 value) internal pure returns (uint72) {\n        require(value \u003c= type(uint72).max, \"SafeCast: value doesn't fit in 72 bits\");\n        return uint72(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint64 from uint256, reverting on\n     * overflow (when the input is greater than largest uint64).\n     *\n     * Counterpart to Solidity's `uint64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint64(uint256 value) internal pure returns (uint64) {\n        require(value \u003c= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n        return uint64(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint56 from uint256, reverting on\n     * overflow (when the input is greater than largest uint56).\n     *\n     * Counterpart to Solidity's `uint56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint56(uint256 value) internal pure returns (uint56) {\n        require(value \u003c= type(uint56).max, \"SafeCast: value doesn't fit in 56 bits\");\n        return uint56(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint48 from uint256, reverting on\n     * overflow (when the input is greater than largest uint48).\n     *\n     * Counterpart to Solidity's `uint48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint48(uint256 value) internal pure returns (uint48) {\n        require(value \u003c= type(uint48).max, \"SafeCast: value doesn't fit in 48 bits\");\n        return uint48(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint40 from uint256, reverting on\n     * overflow (when the input is greater than largest uint40).\n     *\n     * Counterpart to Solidity's `uint40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint40(uint256 value) internal pure returns (uint40) {\n        require(value \u003c= type(uint40).max, \"SafeCast: value doesn't fit in 40 bits\");\n        return uint40(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint32 from uint256, reverting on\n     * overflow (when the input is greater than largest uint32).\n     *\n     * Counterpart to Solidity's `uint32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint32(uint256 value) internal pure returns (uint32) {\n        require(value \u003c= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n        return uint32(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint24 from uint256, reverting on\n     * overflow (when the input is greater than largest uint24).\n     *\n     * Counterpart to Solidity's `uint24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toUint24(uint256 value) internal pure returns (uint24) {\n        require(value \u003c= type(uint24).max, \"SafeCast: value doesn't fit in 24 bits\");\n        return uint24(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint16 from uint256, reverting on\n     * overflow (when the input is greater than largest uint16).\n     *\n     * Counterpart to Solidity's `uint16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint16(uint256 value) internal pure returns (uint16) {\n        require(value \u003c= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n        return uint16(value);\n    }\n\n    /**\n     * @dev Returns the downcasted uint8 from uint256, reverting on\n     * overflow (when the input is greater than largest uint8).\n     *\n     * Counterpart to Solidity's `uint8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v2.5._\n     */\n    function toUint8(uint256 value) internal pure returns (uint8) {\n        require(value \u003c= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n        return uint8(value);\n    }\n\n    /**\n     * @dev Converts a signed int256 into an unsigned uint256.\n     *\n     * Requirements:\n     *\n     * - input must be greater than or equal to 0.\n     *\n     * _Available since v3.0._\n     */\n    function toUint256(int256 value) internal pure returns (uint256) {\n        require(value \u003e= 0, \"SafeCast: value must be positive\");\n        return uint256(value);\n    }\n\n    /**\n     * @dev Returns the downcasted int248 from int256, reverting on\n     * overflow (when the input is less than smallest int248 or\n     * greater than largest int248).\n     *\n     * Counterpart to Solidity's `int248` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 248 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt248(int256 value) internal pure returns (int248 downcasted) {\n        downcasted = int248(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 248 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int240 from int256, reverting on\n     * overflow (when the input is less than smallest int240 or\n     * greater than largest int240).\n     *\n     * Counterpart to Solidity's `int240` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 240 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt240(int256 value) internal pure returns (int240 downcasted) {\n        downcasted = int240(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 240 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int232 from int256, reverting on\n     * overflow (when the input is less than smallest int232 or\n     * greater than largest int232).\n     *\n     * Counterpart to Solidity's `int232` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 232 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt232(int256 value) internal pure returns (int232 downcasted) {\n        downcasted = int232(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 232 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int224 from int256, reverting on\n     * overflow (when the input is less than smallest int224 or\n     * greater than largest int224).\n     *\n     * Counterpart to Solidity's `int224` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 224 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt224(int256 value) internal pure returns (int224 downcasted) {\n        downcasted = int224(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 224 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int216 from int256, reverting on\n     * overflow (when the input is less than smallest int216 or\n     * greater than largest int216).\n     *\n     * Counterpart to Solidity's `int216` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 216 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt216(int256 value) internal pure returns (int216 downcasted) {\n        downcasted = int216(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 216 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int208 from int256, reverting on\n     * overflow (when the input is less than smallest int208 or\n     * greater than largest int208).\n     *\n     * Counterpart to Solidity's `int208` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 208 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt208(int256 value) internal pure returns (int208 downcasted) {\n        downcasted = int208(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 208 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int200 from int256, reverting on\n     * overflow (when the input is less than smallest int200 or\n     * greater than largest int200).\n     *\n     * Counterpart to Solidity's `int200` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 200 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt200(int256 value) internal pure returns (int200 downcasted) {\n        downcasted = int200(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 200 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int192 from int256, reverting on\n     * overflow (when the input is less than smallest int192 or\n     * greater than largest int192).\n     *\n     * Counterpart to Solidity's `int192` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 192 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt192(int256 value) internal pure returns (int192 downcasted) {\n        downcasted = int192(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 192 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int184 from int256, reverting on\n     * overflow (when the input is less than smallest int184 or\n     * greater than largest int184).\n     *\n     * Counterpart to Solidity's `int184` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 184 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt184(int256 value) internal pure returns (int184 downcasted) {\n        downcasted = int184(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 184 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int176 from int256, reverting on\n     * overflow (when the input is less than smallest int176 or\n     * greater than largest int176).\n     *\n     * Counterpart to Solidity's `int176` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 176 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt176(int256 value) internal pure returns (int176 downcasted) {\n        downcasted = int176(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 176 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int168 from int256, reverting on\n     * overflow (when the input is less than smallest int168 or\n     * greater than largest int168).\n     *\n     * Counterpart to Solidity's `int168` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 168 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt168(int256 value) internal pure returns (int168 downcasted) {\n        downcasted = int168(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 168 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int160 from int256, reverting on\n     * overflow (when the input is less than smallest int160 or\n     * greater than largest int160).\n     *\n     * Counterpart to Solidity's `int160` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 160 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt160(int256 value) internal pure returns (int160 downcasted) {\n        downcasted = int160(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 160 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int152 from int256, reverting on\n     * overflow (when the input is less than smallest int152 or\n     * greater than largest int152).\n     *\n     * Counterpart to Solidity's `int152` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 152 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt152(int256 value) internal pure returns (int152 downcasted) {\n        downcasted = int152(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 152 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int144 from int256, reverting on\n     * overflow (when the input is less than smallest int144 or\n     * greater than largest int144).\n     *\n     * Counterpart to Solidity's `int144` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 144 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt144(int256 value) internal pure returns (int144 downcasted) {\n        downcasted = int144(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 144 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int136 from int256, reverting on\n     * overflow (when the input is less than smallest int136 or\n     * greater than largest int136).\n     *\n     * Counterpart to Solidity's `int136` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 136 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt136(int256 value) internal pure returns (int136 downcasted) {\n        downcasted = int136(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 136 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int128 from int256, reverting on\n     * overflow (when the input is less than smallest int128 or\n     * greater than largest int128).\n     *\n     * Counterpart to Solidity's `int128` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 128 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt128(int256 value) internal pure returns (int128 downcasted) {\n        downcasted = int128(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 128 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int120 from int256, reverting on\n     * overflow (when the input is less than smallest int120 or\n     * greater than largest int120).\n     *\n     * Counterpart to Solidity's `int120` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 120 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt120(int256 value) internal pure returns (int120 downcasted) {\n        downcasted = int120(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 120 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int112 from int256, reverting on\n     * overflow (when the input is less than smallest int112 or\n     * greater than largest int112).\n     *\n     * Counterpart to Solidity's `int112` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 112 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt112(int256 value) internal pure returns (int112 downcasted) {\n        downcasted = int112(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 112 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int104 from int256, reverting on\n     * overflow (when the input is less than smallest int104 or\n     * greater than largest int104).\n     *\n     * Counterpart to Solidity's `int104` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 104 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt104(int256 value) internal pure returns (int104 downcasted) {\n        downcasted = int104(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 104 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int96 from int256, reverting on\n     * overflow (when the input is less than smallest int96 or\n     * greater than largest int96).\n     *\n     * Counterpart to Solidity's `int96` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 96 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt96(int256 value) internal pure returns (int96 downcasted) {\n        downcasted = int96(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 96 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int88 from int256, reverting on\n     * overflow (when the input is less than smallest int88 or\n     * greater than largest int88).\n     *\n     * Counterpart to Solidity's `int88` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 88 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt88(int256 value) internal pure returns (int88 downcasted) {\n        downcasted = int88(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 88 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int80 from int256, reverting on\n     * overflow (when the input is less than smallest int80 or\n     * greater than largest int80).\n     *\n     * Counterpart to Solidity's `int80` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 80 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt80(int256 value) internal pure returns (int80 downcasted) {\n        downcasted = int80(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 80 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int72 from int256, reverting on\n     * overflow (when the input is less than smallest int72 or\n     * greater than largest int72).\n     *\n     * Counterpart to Solidity's `int72` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 72 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt72(int256 value) internal pure returns (int72 downcasted) {\n        downcasted = int72(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 72 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int64 from int256, reverting on\n     * overflow (when the input is less than smallest int64 or\n     * greater than largest int64).\n     *\n     * Counterpart to Solidity's `int64` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 64 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt64(int256 value) internal pure returns (int64 downcasted) {\n        downcasted = int64(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 64 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int56 from int256, reverting on\n     * overflow (when the input is less than smallest int56 or\n     * greater than largest int56).\n     *\n     * Counterpart to Solidity's `int56` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 56 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt56(int256 value) internal pure returns (int56 downcasted) {\n        downcasted = int56(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 56 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int48 from int256, reverting on\n     * overflow (when the input is less than smallest int48 or\n     * greater than largest int48).\n     *\n     * Counterpart to Solidity's `int48` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 48 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt48(int256 value) internal pure returns (int48 downcasted) {\n        downcasted = int48(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 48 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int40 from int256, reverting on\n     * overflow (when the input is less than smallest int40 or\n     * greater than largest int40).\n     *\n     * Counterpart to Solidity's `int40` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 40 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt40(int256 value) internal pure returns (int40 downcasted) {\n        downcasted = int40(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 40 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int32 from int256, reverting on\n     * overflow (when the input is less than smallest int32 or\n     * greater than largest int32).\n     *\n     * Counterpart to Solidity's `int32` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 32 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt32(int256 value) internal pure returns (int32 downcasted) {\n        downcasted = int32(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 32 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int24 from int256, reverting on\n     * overflow (when the input is less than smallest int24 or\n     * greater than largest int24).\n     *\n     * Counterpart to Solidity's `int24` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 24 bits\n     *\n     * _Available since v4.7._\n     */\n    function toInt24(int256 value) internal pure returns (int24 downcasted) {\n        downcasted = int24(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 24 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int16 from int256, reverting on\n     * overflow (when the input is less than smallest int16 or\n     * greater than largest int16).\n     *\n     * Counterpart to Solidity's `int16` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 16 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt16(int256 value) internal pure returns (int16 downcasted) {\n        downcasted = int16(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 16 bits\");\n    }\n\n    /**\n     * @dev Returns the downcasted int8 from int256, reverting on\n     * overflow (when the input is less than smallest int8 or\n     * greater than largest int8).\n     *\n     * Counterpart to Solidity's `int8` operator.\n     *\n     * Requirements:\n     *\n     * - input must fit into 8 bits\n     *\n     * _Available since v3.1._\n     */\n    function toInt8(int256 value) internal pure returns (int8 downcasted) {\n        downcasted = int8(value);\n        require(downcasted == value, \"SafeCast: value doesn't fit in 8 bits\");\n    }\n\n    /**\n     * @dev Converts an unsigned uint256 into a signed int256.\n     *\n     * Requirements:\n     *\n     * - input must be less than or equal to maxInt256.\n     *\n     * _Available since v3.0._\n     */\n    function toInt256(uint256 value) internal pure returns (int256) {\n        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n        require(value \u003c= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n        return int256(value);\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length \u003e 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance \u003e= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance \u003e= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length \u003e 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n\n// contracts/base/MultiCallable.sol\n\n/// @notice Collection of Multicall utilities. Fork of Multicall3:\n/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol\nabstract contract MultiCallable {\n    struct Call {\n        bool allowFailure;\n        bytes callData;\n    }\n\n    struct Result {\n        bool success;\n        bytes returnData;\n    }\n\n    /// @notice Aggregates a few calls to this contract into one multicall without modifying `msg.sender`.\n    function multicall(Call[] calldata calls) external returns (Result[] memory callResults) {\n        uint256 amount = calls.length;\n        callResults = new Result[](amount);\n        Call calldata call_;\n        for (uint256 i = 0; i \u003c amount;) {\n            call_ = calls[i];\n            Result memory result = callResults[i];\n            // We perform a delegate call to ourselves here. Delegate call does not modify `msg.sender`, so\n            // this will have the same effect as if `msg.sender` performed all the calls themselves one by one.\n            // solhint-disable-next-line avoid-low-level-calls\n            (result.success, result.returnData) = address(this).delegatecall(call_.callData);\n            // solhint-disable-next-line no-inline-assembly\n            assembly {\n                // Revert if the call fails and failure is not allowed\n                // `allowFailure := calldataload(call_)` and `success := mload(result)`\n                if iszero(or(calldataload(call_), mload(result))) {\n                    // Revert with `0x4d6a2328` (function selector for `MulticallFailed()`)\n                    mstore(0x00, 0x4d6a232800000000000000000000000000000000000000000000000000000000)\n                    revert(0x00, 0x04)\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n    }\n}\n\n// contracts/base/Version.sol\n\n/**\n * @title Versioned\n * @notice Version getter for contracts. Doesn't use any storage slots, meaning\n * it will never cause any troubles with the upgradeable contracts. For instance, this contract\n * can be added or removed from the inheritance chain without shifting the storage layout.\n */\nabstract contract Versioned {\n    /**\n     * @notice Struct that is mimicking the storage layout of a string with 32 bytes or less.\n     * Length is limited by 32, so the whole string payload takes two memory words:\n     * @param length    String length\n     * @param data      String characters\n     */\n    struct _ShortString {\n        uint256 length;\n        bytes32 data;\n    }\n\n    /// @dev Length of the \"version string\"\n    uint256 private immutable _length;\n    /// @dev Bytes representation of the \"version string\".\n    /// Strings with length over 32 are not supported!\n    bytes32 private immutable _data;\n\n    constructor(string memory version_) {\n        _length = bytes(version_).length;\n        if (_length \u003e 32) revert IncorrectVersionLength();\n        // bytes32 is left-aligned =\u003e this will store the byte representation of the string\n        // with the trailing zeroes to complete the 32-byte word\n        _data = bytes32(bytes(version_));\n    }\n\n    function version() external view returns (string memory versionString) {\n        // Load the immutable values to form the version string\n        _ShortString memory str = _ShortString(_length, _data);\n        // The only way to do this cast is doing some dirty assembly\n        assembly {\n            // solhint-disable-previous-line no-inline-assembly\n            versionString := str\n        }\n    }\n}\n\n// contracts/libs/ChainContext.sol\n\n/// @notice Library for accessing chain context variables as tightly packed integers.\n/// Messaging contracts should rely on this library for accessing chain context variables\n/// instead of doing the casting themselves.\nlibrary ChainContext {\n    using SafeCast for uint256;\n\n    /// @notice Returns the current block number as uint40.\n    /// @dev Reverts if block number is greater than 40 bits, which is not supposed to happen\n    /// until the block.timestamp overflows (assuming block time is at least 1 second).\n    function blockNumber() internal view returns (uint40) {\n        return block.number.toUint40();\n    }\n\n    /// @notice Returns the current block timestamp as uint40.\n    /// @dev Reverts if block timestamp is greater than 40 bits, which is\n    /// supposed to happen approximately in year 36835.\n    function blockTimestamp() internal view returns (uint40) {\n        return block.timestamp.toUint40();\n    }\n\n    /// @notice Returns the chain id as uint32.\n    /// @dev Reverts if chain id is greater than 32 bits, which is not\n    /// supposed to happen in production.\n    function chainId() internal view returns (uint32) {\n        return block.chainid.toUint32();\n    }\n}\n\n// contracts/libs/Structures.sol\n\n// Here we define common enums and structures to enable their easier reusing later.\n\n// ═══════════════════════════════ AGENT STATUS ════════════════════════════════\n\n/// @dev Potential statuses for the off-chain bonded agent:\n/// - Unknown: never provided a bond =\u003e signature not valid\n/// - Active: has a bond in BondingManager =\u003e signature valid\n/// - Unstaking: has a bond in BondingManager, initiated the unstaking =\u003e signature not valid\n/// - Resting: used to have a bond in BondingManager, successfully unstaked =\u003e signature not valid\n/// - Fraudulent: proven to commit fraud, value in Merkle Tree not updated =\u003e signature not valid\n/// - Slashed: proven to commit fraud, value in Merkle Tree was updated =\u003e signature not valid\n/// Unstaked agent could later be added back to THE SAME domain by staking a bond again.\n/// Honest agent: Unknown -\u003e Active -\u003e unstaking -\u003e Resting -\u003e Active ...\n/// Malicious agent: Unknown -\u003e Active -\u003e Fraudulent -\u003e Slashed\n/// Malicious agent: Unknown -\u003e Active -\u003e Unstaking -\u003e Fraudulent -\u003e Slashed\nenum AgentFlag {\n    Unknown,\n    Active,\n    Unstaking,\n    Resting,\n    Fraudulent,\n    Slashed\n}\n\n/// @notice Struct for storing an agent in the BondingManager contract.\nstruct AgentStatus {\n    AgentFlag flag;\n    uint32 domain;\n    uint32 index;\n}\n// 184 bits available for tight packing\n\nusing StructureUtils for AgentStatus global;\n\n/// @notice Potential statuses of an agent in terms of being in dispute\n/// - None: agent is not in dispute\n/// - Pending: agent is in unresolved dispute\n/// - Slashed: agent was in dispute that lead to agent being slashed\n/// Note: agent who won the dispute has their status reset to None\nenum DisputeFlag {\n    None,\n    Pending,\n    Slashed\n}\n\n/// @notice Struct for storing dispute status of an agent.\n/// @param flag         Dispute flag: None/Pending/Slashed.\n/// @param openedAt     Timestamp when the latest agent dispute was opened (zero if not opened).\n/// @param resolvedAt   Timestamp when the latest agent dispute was resolved (zero if not resolved).\nstruct DisputeStatus {\n    DisputeFlag flag;\n    uint40 openedAt;\n    uint40 resolvedAt;\n}\n\n// ════════════════════════════════ DESTINATION ════════════════════════════════\n\n/// @notice Struct representing the status of Destination contract.\n/// @param snapRootTime     Timestamp when latest snapshot root was accepted\n/// @param agentRootTime    Timestamp when latest agent root was accepted\n/// @param notaryIndex      Index of Notary who signed the latest agent root\nstruct DestinationStatus {\n    uint40 snapRootTime;\n    uint40 agentRootTime;\n    uint32 notaryIndex;\n}\n\n// ═══════════════════════════════ EXECUTION HUB ═══════════════════════════════\n\n/// @notice Potential statuses of the message in Execution Hub.\n/// - None: there hasn't been a valid attempt to execute the message yet\n/// - Failed: there was a valid attempt to execute the message, but recipient reverted\n/// - Success: there was a valid attempt to execute the message, and recipient did not revert\n/// Note: message can be executed until its status is Success\nenum MessageStatus {\n    None,\n    Failed,\n    Success\n}\n\nlibrary StructureUtils {\n    /// @notice Checks that Agent is Active\n    function verifyActive(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active) {\n            revert AgentNotActive();\n        }\n    }\n\n    /// @notice Checks that Agent is Unstaking\n    function verifyUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Unstaking) {\n            revert AgentNotUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Active or Unstaking\n    function verifyActiveUnstaking(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Active \u0026\u0026 status.flag != AgentFlag.Unstaking) {\n            revert AgentNotActiveNorUnstaking();\n        }\n    }\n\n    /// @notice Checks that Agent is Fraudulent\n    function verifyFraudulent(AgentStatus memory status) internal pure {\n        if (status.flag != AgentFlag.Fraudulent) {\n            revert AgentNotFraudulent();\n        }\n    }\n\n    /// @notice Checks that Agent is not Unknown\n    function verifyKnown(AgentStatus memory status) internal pure {\n        if (status.flag == AgentFlag.Unknown) {\n            revert AgentUnknown();\n        }\n    }\n}\n\n// contracts/libs/merkle/MerkleMath.sol\n\nlibrary MerkleMath {\n    // ═════════════════════════════════════════ BASIC MERKLE CALCULATIONS ═════════════════════════════════════════════\n\n    /**\n     * @notice Calculates the merkle root for the given leaf and merkle proof.\n     * @dev Will revert if proof length exceeds the tree height.\n     * @param index     Index of `leaf` in tree\n     * @param leaf      Leaf of the merkle tree\n     * @param proof     Proof of inclusion of `leaf` in the tree\n     * @param height    Height of the merkle tree\n     * @return root_    Calculated Merkle Root\n     */\n    function proofRoot(uint256 index, bytes32 leaf, bytes32[] memory proof, uint256 height)\n        internal\n        pure\n        returns (bytes32 root_)\n    {\n        // Proof length could not exceed the tree height\n        uint256 proofLen = proof.length;\n        if (proofLen \u003e height) revert TreeHeightTooLow();\n        root_ = leaf;\n        /// @dev Apply unchecked to all ++h operations\n        unchecked {\n            // Go up the tree levels from the leaf following the proof\n            for (uint256 h = 0; h \u003c proofLen; ++h) {\n                // Get a sibling node on current level: this is proof[h]\n                root_ = getParent(root_, proof[h], index, h);\n            }\n            // Go up to the root: the remaining siblings are EMPTY\n            for (uint256 h = proofLen; h \u003c height; ++h) {\n                root_ = getParent(root_, bytes32(0), index, h);\n            }\n        }\n    }\n\n    /**\n     * @notice Calculates the parent of a node on the path from one of the leafs to root.\n     * @param node          Node on a path from tree leaf to root\n     * @param sibling       Sibling for a given node\n     * @param leafIndex     Index of the tree leaf\n     * @param nodeHeight    \"Level height\" for `node` (ZERO for leafs, ORIGIN_TREE_HEIGHT for root)\n     */\n    function getParent(bytes32 node, bytes32 sibling, uint256 leafIndex, uint256 nodeHeight)\n        internal\n        pure\n        returns (bytes32 parent)\n    {\n        // Index for `node` on its \"tree level\" is (leafIndex / 2**height)\n        // \"Left child\" has even index, \"right child\" has odd index\n        if ((leafIndex \u003e\u003e nodeHeight) \u0026 1 == 0) {\n            // Left child\n            return getParent(node, sibling);\n        } else {\n            // Right child\n            return getParent(sibling, node);\n        }\n    }\n\n    /// @notice Calculates the parent of tow nodes in the merkle tree.\n    /// @dev We use implementation with H(0,0) = 0\n    /// This makes EVERY empty node in the tree equal to ZERO,\n    /// saving us from storing H(0,0), H(H(0,0), H(0, 0)), and so on\n    /// @param leftChild    Left child of the calculated node\n    /// @param rightChild   Right child of the calculated node\n    /// @return parent      Value for the node having above mentioned children\n    function getParent(bytes32 leftChild, bytes32 rightChild) internal pure returns (bytes32 parent) {\n        if (leftChild == bytes32(0) \u0026\u0026 rightChild == bytes32(0)) {\n            return 0;\n        } else {\n            return keccak256(bytes.concat(leftChild, rightChild));\n        }\n    }\n\n    // ════════════════════════════════ ROOT/PROOF CALCULATION FOR A LIST OF LEAFS ═════════════════════════════════════\n\n    /**\n     * @notice Calculates merkle root for a list of given leafs.\n     * Merkle Tree is constructed by padding the list with ZERO values for leafs until list length is `2**height`.\n     * Merkle Root is calculated for the constructed tree, and then saved in `leafs[0]`.\n     * \u003e Note:\n     * \u003e - `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * \u003e - Caller is expected not to reuse `hashes` list after the call, and only use `leafs[0]` value,\n     * which is guaranteed to contain the calculated merkle root.\n     * \u003e - root is calculated using the `H(0,0) = 0` Merkle Tree implementation. See MerkleTree.sol for details.\n     * @dev Amount of leaves should be at most `2**height`\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param height    Height of the Merkle Tree to construct\n     */\n    function calculateRoot(bytes32[] memory hashes, uint256 height) internal pure {\n        uint256 levelLength = hashes.length;\n        // Amount of hashes could not exceed amount of leafs in tree with the given height\n        if (levelLength \u003e (1 \u003c\u003c height)) revert TreeHeightTooLow();\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\": the amount of iterations for the for loop above.\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n            }\n        }\n    }\n\n    /**\n     * @notice Generates a proof of inclusion of a leaf in the list. If the requested index is outside\n     * of the list range, generates a proof of inclusion for an empty leaf (proof of non-inclusion).\n     * The Merkle Tree is constructed by padding the list with ZERO values until list length is a power of two\n     * __AND__ index is in the extended list range. For example:\n     *  - `hashes.length == 6` and `0 \u003c= index \u003c= 7` will \"extend\" the list to 8 entries.\n     *  - `hashes.length == 6` and `7 \u003c index \u003c= 15` will \"extend\" the list to 16 entries.\n     * \u003e Note: `leafs` values are overwritten in the process to avoid excessive memory allocations.\n     * Caller is expected not to reuse `hashes` list after the call.\n     * @param hashes    List of leafs for the merkle tree (to be overwritten)\n     * @param index     Leaf index to generate the proof for\n     * @return proof    Generated merkle proof\n     */\n    function calculateProof(bytes32[] memory hashes, uint256 index) internal pure returns (bytes32[] memory proof) {\n        // Use only meaningful values for the shortened proof\n        // Check if index is within the list range (we want to generates proofs for outside leafs as well)\n        uint256 height = getHeight(index \u003c hashes.length ? hashes.length : (index + 1));\n        proof = new bytes32[](height);\n        uint256 levelLength = hashes.length;\n        /// @dev h, leftIndex, rightIndex and levelLength never overflow\n        unchecked {\n            // Iterate `height` levels up from the leaf level\n            // For every level we will only record \"significant values\", i.e. not equal to ZERO\n            for (uint256 h = 0; h \u003c height; ++h) {\n                // Use sibling for the merkle proof; `index^1` is index of our sibling\n                proof[h] = (index ^ 1 \u003c levelLength) ? hashes[index ^ 1] : bytes32(0);\n\n                // Let H be the height of the \"current level\". H = 0 for the \"leafs level\".\n                // Invariant: a total of 2**(HEIGHT-H) nodes are on the current level\n                // Invariant: hashes[0 .. length) are \"significant values\" for the \"current level\" nodes\n                // Invariant: bytes32(0) is the value for nodes with indexes [length .. 2**(HEIGHT-H))\n\n                // Iterate over every pair of (leftChild, rightChild) on the current level\n                for (uint256 leftIndex = 0; leftIndex \u003c levelLength; leftIndex += 2) {\n                    uint256 rightIndex = leftIndex + 1;\n                    bytes32 leftChild = hashes[leftIndex];\n                    // Note: rightChild might be ZERO\n                    bytes32 rightChild = rightIndex \u003c levelLength ? hashes[rightIndex] : bytes32(0);\n                    // Record the parent hash in the same array. This will not affect\n                    // further calculations for the same level: (leftIndex \u003e\u003e 1) \u003c= leftIndex.\n                    hashes[leftIndex \u003e\u003e 1] = getParent(leftChild, rightChild);\n                }\n                // Set length for the \"parent level\"\n                levelLength = (levelLength + 1) \u003e\u003e 1;\n                // Traverse to parent node\n                index \u003e\u003e= 1;\n            }\n        }\n    }\n\n    /// @notice Returns the height of the tree having a given amount of leafs.\n    function getHeight(uint256 leafs) internal pure returns (uint256 height) {\n        uint256 amount = 1;\n        while (amount \u003c leafs) {\n            unchecked {\n                ++height;\n            }\n            amount \u003c\u003c= 1;\n        }\n    }\n}\n\n// contracts/libs/stack/GasData.sol\n\n/// GasData in encoded data with \"basic information about gas prices\" for some chain.\ntype GasData is uint96;\n\nusing GasDataLib for GasData global;\n\n/// ChainGas is encoded data with given chain's \"basic information about gas prices\".\ntype ChainGas is uint128;\n\nusing GasDataLib for ChainGas global;\n\n/// Library for encoding and decoding GasData and ChainGas structs.\n/// # GasData\n/// `GasData` is a struct to store the \"basic information about gas prices\", that could\n/// be later used to approximate the cost of a message execution, and thus derive the\n/// minimal tip values for sending a message to the chain.\n/// \u003e - `GasData` is supposed to be cached by `GasOracle` contract, allowing to store the\n/// \u003e approximates instead of the exact values, and thus save on storage costs.\n/// \u003e - For instance, if `GasOracle` only updates the values on +- 10% change, having an\n/// \u003e 0.4% error on the approximates would be acceptable.\n/// `GasData` is supposed to be included in the Origin's state, which are synced across\n/// chains using Agent-signed snapshots and attestations.\n/// ## GasData stack layout (from highest bits to lowest)\n///\n/// | Position   | Field        | Type   | Bytes | Description                                         |\n/// | ---------- | ------------ | ------ | ----- | --------------------------------------------------- |\n/// | (012..010] | gasPrice     | uint16 | 2     | Gas price for the chain (in Wei per gas unit)       |\n/// | (010..008] | dataPrice    | uint16 | 2     | Calldata price (in Wei per byte of content)         |\n/// | (008..006] | execBuffer   | uint16 | 2     | Tx fee safety buffer for message execution (in Wei) |\n/// | (006..004] | amortAttCost | uint16 | 2     | Amortized cost for attestation submission (in Wei)  |\n/// | (004..002] | etherPrice   | uint16 | 2     | Chain's Ether Price / Mainnet Ether Price (in BWAD) |\n/// | (002..000] | markup       | uint16 | 2     | Markup for the message execution (in BWAD)          |\n/// \u003e See Number.sol for more details on `Number` type and BWAD (binary WAD) math.\n///\n/// ## ChainGas stack layout (from highest bits to lowest)\n///\n/// | Position   | Field   | Type   | Bytes | Description      |\n/// | ---------- | ------- | ------ | ----- | ---------------- |\n/// | (016..004] | gasData | uint96 | 12    | Chain's gas data |\n/// | (004..000] | domain  | uint32 | 4     | Chain's domain   |\nlibrary GasDataLib {\n    /// @dev Amount of bits to shift to gasPrice field\n    uint96 private constant SHIFT_GAS_PRICE = 10 * 8;\n    /// @dev Amount of bits to shift to dataPrice field\n    uint96 private constant SHIFT_DATA_PRICE = 8 * 8;\n    /// @dev Amount of bits to shift to execBuffer field\n    uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;\n    /// @dev Amount of bits to shift to amortAttCost field\n    uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;\n    /// @dev Amount of bits to shift to etherPrice field\n    uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;\n\n    /// @dev Amount of bits to shift to gasData field\n    uint128 private constant SHIFT_GAS_DATA = 4 * 8;\n\n    // ═════════════════════════════════════════════════ GAS DATA ══════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded GasData struct with the given fields.\n    /// @param gasPrice_        Gas price for the chain (in Wei per gas unit)\n    /// @param dataPrice_       Calldata price (in Wei per byte of content)\n    /// @param execBuffer_      Tx fee safety buffer for message execution (in Wei)\n    /// @param amortAttCost_    Amortized cost for attestation submission (in Wei)\n    /// @param etherPrice_      Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)\n    /// @param markup_          Markup for the message execution (in BWAD)\n    function encodeGasData(\n        Number gasPrice_,\n        Number dataPrice_,\n        Number execBuffer_,\n        Number amortAttCost_,\n        Number etherPrice_,\n        Number markup_\n    ) internal pure returns (GasData) {\n        // Number type wraps uint16, so could safely be casted to uint96\n        // forgefmt: disable-next-item\n        return GasData.wrap(\n            uint96(Number.unwrap(gasPrice_)) \u003c\u003c SHIFT_GAS_PRICE |\n            uint96(Number.unwrap(dataPrice_)) \u003c\u003c SHIFT_DATA_PRICE |\n            uint96(Number.unwrap(execBuffer_)) \u003c\u003c SHIFT_EXEC_BUFFER |\n            uint96(Number.unwrap(amortAttCost_)) \u003c\u003c SHIFT_AMORT_ATT_COST |\n            uint96(Number.unwrap(etherPrice_)) \u003c\u003c SHIFT_ETHER_PRICE |\n            uint96(Number.unwrap(markup_))\n        );\n    }\n\n    /// @notice Wraps padded uint256 value into GasData struct.\n    function wrapGasData(uint256 paddedGasData) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(paddedGasData));\n    }\n\n    /// @notice Returns the gas price, in Wei per gas unit.\n    function gasPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_GAS_PRICE));\n    }\n\n    /// @notice Returns the calldata price, in Wei per byte of content.\n    function dataPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_DATA_PRICE));\n    }\n\n    /// @notice Returns the tx fee safety buffer for message execution, in Wei.\n    function execBuffer(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_EXEC_BUFFER));\n    }\n\n    /// @notice Returns the amortized cost for attestation submission, in Wei.\n    function amortAttCost(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_AMORT_ATT_COST));\n    }\n\n    /// @notice Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.\n    function etherPrice(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data) \u003e\u003e SHIFT_ETHER_PRICE));\n    }\n\n    /// @notice Returns the markup for the message execution, in BWAD math.\n    function markup(GasData data) internal pure returns (Number) {\n        // Casting to uint16 will truncate the highest bits, which is the behavior we want\n        return Number.wrap(uint16(GasData.unwrap(data)));\n    }\n\n    // ════════════════════════════════════════════════ CHAIN DATA ═════════════════════════════════════════════════════\n\n    /// @notice Returns an encoded ChainGas struct with the given fields.\n    /// @param gasData_ Chain's gas data\n    /// @param domain_  Chain's domain\n    function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas) {\n        // GasData type wraps uint96, so could safely be casted to uint128\n        return ChainGas.wrap(uint128(GasData.unwrap(gasData_)) \u003c\u003c SHIFT_GAS_DATA | uint128(domain_));\n    }\n\n    /// @notice Wraps padded uint256 value into ChainGas struct.\n    function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas) {\n        // Casting to uint128 will truncate the highest bits, which is the behavior we want\n        return ChainGas.wrap(uint128(paddedChainGas));\n    }\n\n    /// @notice Returns the chain's gas data.\n    function gasData(ChainGas data) internal pure returns (GasData) {\n        // Casting to uint96 will truncate the highest bits, which is the behavior we want\n        return GasData.wrap(uint96(ChainGas.unwrap(data) \u003e\u003e SHIFT_GAS_DATA));\n    }\n\n    /// @notice Returns the chain's domain.\n    function domain(ChainGas data) internal pure returns (uint32) {\n        // Casting to uint32 will truncate the highest bits, which is the behavior we want\n        return uint32(ChainGas.unwrap(data));\n    }\n\n    /// @notice Returns the hash for the list of ChainGas structs.\n    function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_) {\n        // Use assembly to calculate the hash of the array without copying it\n        // ChainGas takes a single word of storage, thus ChainGas[] is stored in the following way:\n        // 0x00: length of the array, in words\n        // 0x20: first ChainGas struct\n        // 0x40: second ChainGas struct\n        // And so on...\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            // Find the location where the array data starts, we add 0x20 to skip the length field\n            let loc := add(snapGas, 0x20)\n            // Load the length of the array (in words).\n            // Shifting left 5 bits is equivalent to multiplying by 32: this converts from words to bytes.\n            let len := shl(5, mload(snapGas))\n            // Calculate the hash of the array\n            snapGasHash_ := keccak256(loc, len)\n        }\n    }\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```solidity\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n *\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts.\n     *\n     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n     * constructor.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = !_initializing;\n        require(\n            (isTopLevelCall \u0026\u0026 _initialized \u003c 1) || (!AddressUpgradeable.isContract(address(this)) \u0026\u0026 _initialized == 1),\n            \"Initializable: contract is already initialized\"\n        );\n        _initialized = 1;\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n     * are added through upgrades and that require initialization.\n     *\n     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n     * cannot be nested. If one is invoked in the context of another, execution will revert.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     *\n     * WARNING: setting the version to 255 will prevent any future reinitialization.\n     *\n     * Emits an {Initialized} event.\n     */\n    modifier reinitializer(uint8 version) {\n        require(!_initializing \u0026\u0026 _initialized \u003c version, \"Initializable: contract is already initialized\");\n        _initialized = version;\n        _initializing = true;\n        _;\n        _initializing = false;\n        emit Initialized(version);\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     *\n     * Emits an {Initialized} event the first time it is successfully executed.\n     */\n    function _disableInitializers() internal virtual {\n        require(!_initializing, \"Initializable: contract is initializing\");\n        if (_initialized != type(uint8).max) {\n            _initialized = type(uint8).max;\n            emit Initialized(type(uint8).max);\n        }\n    }\n\n    /**\n     * @dev Returns the highest version that has been initialized. See {reinitializer}.\n     */\n    function _getInitializedVersion() internal view returns (uint8) {\n        return _initialized;\n    }\n\n    /**\n     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.\n     */\n    function _isInitializing() internal view returns (bool) {\n        return _initializing;\n    }\n}\n\n// contracts/events/AgentManagerEvents.sol\n\nabstract contract AgentManagerEvents {\n    /**\n     * @notice Emitted whenever a Dispute is opened between two agents. This happens when a Guard submits\n     * their report for the Notary-signed statement to `StatementInbox`.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    event DisputeOpened(uint256 disputeIndex, uint32 guardIndex, uint32 notaryIndex);\n\n    /**\n     * @notice Emitted whenever a Dispute is resolved. This happens when an Agent who was in Dispute is slashed.\n     * Note: this won't be emitted, if an Agent was slashed without being in Dispute.\n     * @param disputeIndex  Index of the dispute in the global list of all opened disputes\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the rival agent in the Agent Merkle Tree\n     * @param fraudProver   Address who provided fraud proof to resolve the Dispute\n     */\n    event DisputeResolved(uint256 disputeIndex, uint32 slashedIndex, uint32 rivalIndex, address fraudProver);\n\n    // ═══════════════════════════════════════════════ DATA UPDATED ════════════════════════════════════════════════════\n\n    /**\n     * @notice Emitted whenever the root of the Agent Merkle Tree is updated.\n     * @param newRoot   New agent merkle root\n     */\n    event RootUpdated(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner proposes a new agent root to resolve the stuck chain.\n     * @param newRoot   New agent merkle root that was proposed\n     */\n    event AgentRootProposed(bytes32 newRoot);\n\n    /**\n     * @notice Emitted after the contract owner cancels the previously proposed agent root.\n     * @param proposedRoot  Agent merkle root that was proposed\n     */\n    event ProposedAgentRootCancelled(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted after the contract owner resolves the previously proposed agent root.\n     * @param proposedRoot  New agent merkle root that was resolved\n     */\n    event ProposedAgentRootResolved(bytes32 proposedRoot);\n\n    /**\n     * @notice Emitted whenever a status of the agent is updated.\n     * @dev Only Active/Unstaking/Resting/Slashed flags could be stored in the Agent Merkle Tree.\n     * Unknown flag is the default (zero) value and is used to represent agents that never\n     * interacted with the BondingManager contract.\n     * Fraudulent flag is the value for the agent who has been proven to commit fraud, but their\n     * status hasn't been updated to Slashed in the Agent Merkle Tree. This is due to the fact\n     * that the update of the status requires a merkle proof of the old status, and happens\n     * in a separate transaction because of that.\n     * @param flag      Flag defining agent status:\n     * @param domain    Domain assigned to the agent (ZERO for Guards)\n     * @param agent     Agent address\n     */\n    event StatusUpdated(AgentFlag flag, uint32 indexed domain, address indexed agent);\n}\n\n// contracts/interfaces/IAgentManager.sol\n\ninterface IAgentManager {\n    /**\n     * @notice Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Guard or Notary is already in Dispute.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Allows Inbox to slash an agent, if their fraud was proven.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Caller is not Inbox.\n     * \u003e - Domain doesn't match the saved agent domain.\n     * @param domain    Domain where the Agent is active\n     * @param agent     Address of the Agent\n     * @param prover    Address that initially provided fraud proof\n     */\n    function slashAgent(uint32 domain, address agent, address prover) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest known root of the Agent Merkle Tree.\n     */\n    function agentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns the number of opened Disputes.\n     * @dev This includes the Disputes that have been resolved already.\n     */\n    function getDisputesAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns information about the dispute with the given index.\n     * @dev Will revert if dispute with given index hasn't been opened yet.\n     * @param index             Dispute index\n     * @return guard            Address of the Guard in the Dispute\n     * @return notary           Address of the Notary in the Dispute\n     * @return slashedAgent     Address of the Agent who was slashed when Dispute was resolved\n     * @return fraudProver      Address who provided fraud proof to resolve the Dispute\n     * @return reportPayload    Raw payload with report data that led to the Dispute\n     * @return reportSignature  Guard signature for the report payload\n     */\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        );\n\n    /**\n     * @notice Returns the current Dispute status of a given agent. See Structures.sol for details.\n     * @dev Every returned value will be set to zero if agent was not slashed and is not in Dispute.\n     * `rival` and `disputePtr` will be set to zero if the agent was slashed without being in Dispute.\n     * @param agent         Agent address\n     * @return flag         Flag describing the current Dispute status for the agent: None/Pending/Slashed\n     * @return rival        Address of the rival agent in the Dispute\n     * @return fraudProver  Address who provided fraud proof to resolve the Dispute\n     * @return disputePtr   Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.\n     */\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);\n}\n\n// contracts/interfaces/IAgentSecured.sol\n\ninterface IAgentSecured {\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * between a Guard and a Notary has been opened.\n     * @param guardIndex    Index of the Guard in the Agent Merkle Tree\n     * @param notaryIndex   Index of the Notary in the Agent Merkle Tree\n     */\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external;\n\n    /**\n     * @notice Local AgentManager should call this function to indicate that a dispute\n     * has been resolved due to one of the agents being slashed.\n     * \u003e `rivalIndex` will be ZERO, if the slashed agent was not in the Dispute.\n     * @param slashedIndex  Index of the slashed agent in the Agent Merkle Tree\n     * @param rivalIndex    Index of the their Dispute Rival in the Agent Merkle Tree\n     */\n    function resolveDispute(uint32 slashedIndex, uint32 rivalIndex) external;\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the address of the local AgentManager contract, which is treated as\n     * the \"source of truth\" for agent statuses.\n     */\n    function agentManager() external view returns (address);\n\n    /**\n     * @notice Returns the address of the local Inbox contract, which is treated as\n     * the \"source of truth\" for agent-signed statements.\n     * @dev Inbox passes verified agent statements to `IAgentSecured` contract.\n     */\n    function inbox() external view returns (address);\n\n    /**\n     * @notice Returns (flag, domain, index) for a given agent. See Structures.sol for details.\n     * @dev Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud,\n     * but their status is not updated to Slashed yet.\n     * @param agent     Agent address\n     * @return          Status for the given agent: (flag, domain, index).\n     */\n    function agentStatus(address agent) external view returns (AgentStatus memory);\n\n    /**\n     * @notice Returns agent address and their current status for a given agent index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param index     Agent index in the Agent Merkle Tree\n     * @return agent    Agent address\n     * @return status   Status for the given agent: (flag, domain, index)\n     */\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);\n\n    /**\n     * @notice Returns (flag, openedAt, resolvedAt) that describes the latest status of\n     * the latest dispute for an agent with a given index.\n     * @dev Will return empty values if agent with given index doesn't exist.\n     * @param agentIndex    Agent index in the Agent Merkle Tree\n     * @return              Latest dispute status for the given agent: (flag, openedAt, resolvedAt)\n     */\n    function latestDisputeStatus(uint32 agentIndex) external view returns (DisputeStatus memory);\n}\n\n// contracts/interfaces/InterfaceDestination.sol\n\ninterface InterfaceDestination {\n    /**\n     * @notice Attempts to pass a quarantined Agent Merkle Root to a local Light Manager.\n     * @dev Will do nothing, if root optimistic period is not over.\n     * @return rootPending  Whether there is a pending agent merkle root left\n     */\n    function passAgentRoot() external returns (bool rootPending);\n\n    /**\n     * @notice Accepts an attestation, which local `AgentManager` verified to have been signed\n     * by an active Notary for this chain.\n     * \u003e Attestation is created whenever a Notary-signed snapshot is saved in Summit on Synapse Chain.\n     * - Saved Attestation could be later used to prove the inclusion of message in the Origin Merkle Tree.\n     * - Messages coming from chains included in the Attestation's snapshot could be proven.\n     * - Proof only exists for messages that were sent prior to when the Attestation's snapshot was taken.\n     * \u003e Will revert if any of these is true:\n     * \u003e - Called by anyone other than local `AgentManager`.\n     * \u003e - Attestation payload is not properly formatted.\n     * \u003e - Attestation signer is in Dispute.\n     * \u003e - Attestation's snapshot root has been previously submitted.\n     * Note: agentRoot and snapGas have been verified by the local `AgentManager`.\n     * @param notaryIndex       Index of Attestation Notary in Agent Merkle Tree\n     * @param sigIndex          Index of stored Notary signature\n     * @param attPayload        Raw payload with Attestation data\n     * @param agentRoot         Agent Merkle Root from the Attestation\n     * @param snapGas           Gas data for each chain in the Attestation's snapshot\n     * @return wasAccepted      Whether the Attestation was accepted\n     */\n    function acceptAttestation(\n        uint32 notaryIndex,\n        uint256 sigIndex,\n        bytes memory attPayload,\n        bytes32 agentRoot,\n        ChainGas[] memory snapGas\n    ) external returns (bool wasAccepted);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the total amount of Notaries attestations that have been accepted.\n     */\n    function attestationsAmount() external view returns (uint256);\n\n    /**\n     * @notice Returns a Notary-signed attestation with a given index.\n     * \u003e Index refers to the list of all attestations accepted by this contract.\n     * @dev Attestations are created on Synapse Chain whenever a Notary-signed snapshot is accepted by Summit.\n     * Will return an empty signature if this contract is deployed on Synapse Chain.\n     * @param index             Attestation index\n     * @return attPayload       Raw payload with Attestation data\n     * @return attSignature     Notary signature for the reported attestation\n     */\n    function getAttestation(uint256 index) external view returns (bytes memory attPayload, bytes memory attSignature);\n\n    /**\n     * @notice Returns the gas data for a given chain from the latest accepted attestation with that chain.\n     * @dev Will return empty values if there is no data for the domain,\n     * or if the notary who provided the data is in dispute.\n     * @param domain            Domain for the chain\n     * @return gasData          Gas data for the chain\n     * @return dataMaturity     Gas data age in seconds\n     */\n    function getGasData(uint32 domain) external view returns (GasData gasData, uint256 dataMaturity);\n\n    /**\n     * Returns status of Destination contract as far as snapshot/agent roots are concerned\n     * @return snapRootTime     Timestamp when latest snapshot root was accepted\n     * @return agentRootTime    Timestamp when latest agent root was accepted\n     * @return notaryIndex      Index of Notary who signed the latest agent root\n     */\n    function destStatus() external view returns (uint40 snapRootTime, uint40 agentRootTime, uint32 notaryIndex);\n\n    /**\n     * Returns Agent Merkle Root to be passed to LightManager once its optimistic period is over.\n     */\n    function nextAgentRoot() external view returns (bytes32);\n\n    /**\n     * @notice Returns the nonce of the last attestation submitted by a Notary with a given agent index.\n     * @dev Will return zero if the Notary hasn't submitted any attestations yet.\n     */\n    function lastAttestationNonce(uint32 notaryIndex) external view returns (uint32);\n}\n\n// contracts/interfaces/InterfaceLightManager.sol\n\ninterface InterfaceLightManager {\n    /**\n     * @notice Updates agent status, using a proof against the latest known Agent Merkle Root.\n     * @dev Will revert if the provided proof doesn't match the latest merkle root.\n     * @param agent     Agent address\n     * @param status    Structure specifying agent status: (flag, domain, index)\n     * @param proof     Merkle proof of Active status for the agent\n     */\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;\n\n    /**\n     * @notice Updates the root of Agent Merkle Tree that the Light Manager is tracking.\n     * Could be only called by a local Destination contract, which is supposed to\n     * verify the attested Agent Merkle Roots.\n     * @param agentRoot_    New Agent Merkle Root\n     */\n    function setAgentRoot(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to set the agent root to resolve the \"stuck\" chain\n     * by proposing the new agent root. The contract owner will be able to resolve the proposed\n     * agent root after a certain period of time.\n     * Note: this function could be called multiple times, each time the timer will be reset.\n     * This could only be called if no fresh data has been submitted by the Notaries to the Inbox,\n     * indicating that the chain is stuck for one of the reasons:\n     * - All active Notaries are in Dispute.\n     * - No active Notaries exist under the current agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - Agent root is empty.\n     * - The chain is not in a stuck state (has recently received a fresh data from the Notaries).\n     * @param agentRoot_    New Agent Merkle Root that is proposed to be set\n     */\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external;\n\n    /**\n     * @notice Allows contract owner to cancel the previously proposed agent root.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     */\n    function cancelProposedAgentRoot() external;\n\n    /**\n     * @notice Allows contract owner to resolve the previously proposed agent root.\n     * This will update the agent root, allowing the agents to update their status, effectively\n     * resolving the \"stuck\" chain.\n     * @dev Will revert if any of the following conditions is met:\n     * - Caller is not the contract owner.\n     * - No agent root was proposed.\n     * - Not enough time has passed since the agent root was proposed.\n     */\n    function resolveProposedAgentRoot() external;\n\n    /**\n     * @notice Withdraws locked base message tips from local Origin to the recipient.\n     * @dev Could only be remote-called by BondingManager contract on Synapse Chain.\n     * Note: as an extra security check this function returns its own selector, so that\n     * Destination could verify that a \"remote\" function was called when executing a manager message.\n     * @param recipient     Address to withdraw tips to\n     * @param amount        Tips value to withdraw\n     */\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue);\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /**\n     * @notice Returns the latest proposed agent root and the timestamp when it was proposed.\n     * @dev Will return zero values if no agent root was proposed, or if the proposed agent root\n     * was already resolved.\n     */\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol\n\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n    function __Context_init() internal onlyInitializing {\n    }\n\n    function __Context_init_unchained() internal onlyInitializing {\n    }\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[50] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    function __Ownable_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable_init_unchained() internal onlyInitializing {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// node_modules/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol\n\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {\n    function __Ownable2Step_init() internal onlyInitializing {\n        __Ownable_init_unchained();\n    }\n\n    function __Ownable2Step_init_unchained() internal onlyInitializing {\n    }\n    address private _pendingOwner;\n\n    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Returns the address of the pending owner.\n     */\n    function pendingOwner() public view virtual returns (address) {\n        return _pendingOwner;\n    }\n\n    /**\n     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual override onlyOwner {\n        _pendingOwner = newOwner;\n        emit OwnershipTransferStarted(owner(), newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual override {\n        delete _pendingOwner;\n        super._transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev The new owner accepts the ownership transfer.\n     */\n    function acceptOwnership() public virtual {\n        address sender = _msgSender();\n        require(pendingOwner() == sender, \"Ownable2Step: caller is not the new owner\");\n        _transferOwnership(sender);\n    }\n\n    /**\n     * @dev This empty reserved space is put in place to allow future versions to add new\n     * variables without shifting down storage in the inheritance chain.\n     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n     */\n    uint256[49] private __gap;\n}\n\n// contracts/base/MessagingBase.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════\n\n/**\n * @notice Base contract for all messaging contracts.\n * - Provides context on the local chain's domain.\n * - Provides ownership functionality.\n * - Will be providing pausing functionality when it is implemented.\n */\nabstract contract MessagingBase is MultiCallable, Versioned, Ownable2StepUpgradeable {\n    // ════════════════════════════════════════════════ IMMUTABLES ═════════════════════════════════════════════════════\n\n    /// @notice Domain of the local chain, set once upon contract creation\n    uint32 public immutable localDomain;\n    // @notice Domain of the Synapse chain, set once upon contract creation\n    uint32 public immutable synapseDomain;\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    /// @dev gap for upgrade safety\n    uint256[50] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    constructor(string memory version_, uint32 synapseDomain_) Versioned(version_) {\n        localDomain = ChainContext.chainId();\n        synapseDomain = synapseDomain_;\n    }\n\n    // TODO: Implement pausing\n\n    /**\n     * @dev Should be impossible to renounce ownership;\n     * we override OpenZeppelin OwnableUpgradeable's\n     * implementation of renounceOwnership to make it a no-op\n     */\n    function renounceOwnership() public override onlyOwner {} //solhint-disable-line no-empty-blocks\n}\n\n// contracts/manager/AgentManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice `AgentManager` is used to keep track of all the bonded agents and their statuses.\n/// The exact logic of how the agent statuses are stored and updated is implemented in child contracts,\n/// and depends on whether the contract is used on Synapse Chain or on other chains.\n/// `AgentManager` is responsible for the following:\n/// - Keeping track of all the bonded agents and their statuses.\n/// - Keeping track of all the disputes between agents.\n/// - Notifying `AgentSecured` contracts about the opened and resolved disputes.\n/// - Notifying `AgentSecured` contracts about the slashed agents.\nabstract contract AgentManager is MessagingBase, AgentManagerEvents, IAgentManager {\n    struct AgentDispute {\n        DisputeFlag flag;\n        uint88 disputePtr;\n        address fraudProver;\n    }\n\n    // TODO: do we want to store the dispute timestamp?\n    struct OpenedDispute {\n        uint32 guardIndex;\n        uint32 notaryIndex;\n        uint32 slashedIndex;\n    }\n\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n\n    address public origin;\n\n    address public destination;\n\n    address public inbox;\n\n    // (agent index =\u003e their dispute status)\n    mapping(uint256 =\u003e AgentDispute) internal _agentDispute;\n\n    // All disputes ever opened\n    OpenedDispute[] internal _disputes;\n\n    /// @dev gap for upgrade safety\n    uint256[45] private __GAP; // solhint-disable-line var-name-mixedcase\n\n    modifier onlyInbox() {\n        if (msg.sender != inbox) revert CallerNotInbox();\n        _;\n    }\n\n    modifier onlyWhenStuck() {\n        // Check if there has been no fresh data from the Notaries for a while.\n        (uint40 snapRootTime,,) = InterfaceDestination(destination).destStatus();\n        if (block.timestamp \u003c FRESH_DATA_TIMEOUT + snapRootTime) revert NotStuck();\n        _;\n    }\n\n    // ════════════════════════════════════════════════ INITIALIZER ════════════════════════════════════════════════════\n\n    // solhint-disable-next-line func-name-mixedcase\n    function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing {\n        origin = origin_;\n        destination = destination_;\n        inbox = inbox_;\n    }\n\n    // ════════════════════════════════════════════════ ONLY INBOX ═════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    // solhint-disable-next-line ordering\n    function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox {\n        // Check that both agents are not in Dispute yet.\n        if (_agentDispute[guardIndex].flag != DisputeFlag.None) revert GuardInDispute();\n        if (_agentDispute[notaryIndex].flag != DisputeFlag.None) revert NotaryInDispute();\n        _disputes.push(OpenedDispute(guardIndex, notaryIndex, 0));\n        // Dispute is stored at length - 1, but we store the index + 1 to distinguish from \"not in dispute\".\n        // TODO: check if we really need to use 88 bits for dispute indexes. Every dispute ends up in one of\n        // the agents being slashed, so the number of disputes is limited by the number of agents (currently 2**32).\n        // Thus we can do the unsafe cast to uint88.\n        uint88 disputePtr = uint88(_disputes.length);\n        _agentDispute[guardIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        _agentDispute[notaryIndex] = AgentDispute(DisputeFlag.Pending, disputePtr, address(0));\n        // Dispute index is length - 1. Note: report that initiated the dispute has the same index in `Inbox`.\n        emit DisputeOpened({disputeIndex: disputePtr - 1, guardIndex: guardIndex, notaryIndex: notaryIndex});\n        _notifyDisputeOpened(guardIndex, notaryIndex);\n    }\n\n    /// @inheritdoc IAgentManager\n    function slashAgent(uint32 domain, address agent, address prover) external onlyInbox {\n        _slashAgent(domain, agent, prover);\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc IAgentManager\n    function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status) {\n        agent = _getAgent(index);\n        if (agent != address(0)) status = agentStatus(agent);\n    }\n\n    /// @inheritdoc IAgentManager\n    function agentStatus(address agent) public view returns (AgentStatus memory status) {\n        status = _storedAgentStatus(agent);\n        // If agent was proven to commit fraud, but their slashing wasn't completed, return the Fraudulent flag.\n        if (_agentDispute[_getIndex(agent)].flag == DisputeFlag.Slashed \u0026\u0026 status.flag != AgentFlag.Slashed) {\n            status.flag = AgentFlag.Fraudulent;\n        }\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDisputesAmount() external view returns (uint256) {\n        return _disputes.length;\n    }\n\n    /// @inheritdoc IAgentManager\n    function getDispute(uint256 index)\n        external\n        view\n        returns (\n            address guard,\n            address notary,\n            address slashedAgent,\n            address fraudProver,\n            bytes memory reportPayload,\n            bytes memory reportSignature\n        )\n    {\n        if (index \u003e= _disputes.length) revert IndexOutOfRange();\n        OpenedDispute memory dispute = _disputes[index];\n        guard = _getAgent(dispute.guardIndex);\n        notary = _getAgent(dispute.notaryIndex);\n        if (dispute.slashedIndex \u003e 0) {\n            slashedAgent = _getAgent(dispute.slashedIndex);\n            fraudProver = _agentDispute[dispute.slashedIndex].fraudProver;\n        }\n        (reportPayload, reportSignature) = IStatementInbox(inbox).getGuardReport(index);\n    }\n\n    /// @inheritdoc IAgentManager\n    function disputeStatus(address agent)\n        external\n        view\n        returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr)\n    {\n        uint256 agentIndex = _getIndex(agent);\n        AgentDispute memory agentDispute = _agentDispute[agentIndex];\n        flag = agentDispute.flag;\n        fraudProver = agentDispute.fraudProver;\n        disputePtr = agentDispute.disputePtr;\n        if (disputePtr \u003e 0) {\n            OpenedDispute memory dispute = _disputes[disputePtr - 1];\n            rival = _getAgent(dispute.guardIndex == agentIndex ? dispute.notaryIndex : dispute.guardIndex);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    /// @dev Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.\n    // solhint-disable-next-line no-empty-blocks\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual {}\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;\n\n    /// @dev Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;\n\n    /// @dev Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent.\n    /// Should be called when the agent fraud was confirmed.\n    function _slashAgent(uint32 domain, address agent, address prover) internal {\n        // Check that agent is Active/Unstaking and that the domains match\n        AgentStatus memory status = _storedAgentStatus(agent);\n        status.verifyActiveUnstaking();\n        if (status.domain != domain) revert IncorrectAgentDomain();\n        // The \"stored\" agent status is not updated yet, however agentStatus() will return AgentFlag.Fraudulent\n        emit StatusUpdated(AgentFlag.Fraudulent, domain, agent);\n        // This will revert if the agent has been slashed earlier\n        _resolveDispute(status.index, prover);\n        // Call \"after slash\" hook - this allows Bonding/Light Manager to add custom \"after slash\" logic\n        _afterAgentSlashed(domain, agent, prover);\n    }\n\n    /// @dev Resolves a Dispute between a slashed Agent and their Rival (if there was one).\n    function _resolveDispute(uint32 slashedIndex, address prover) internal {\n        AgentDispute memory agentDispute = _agentDispute[slashedIndex];\n        if (agentDispute.flag == DisputeFlag.Slashed) revert DisputeAlreadyResolved();\n        agentDispute.flag = DisputeFlag.Slashed;\n        agentDispute.fraudProver = prover;\n        _agentDispute[slashedIndex] = agentDispute;\n        // Check if there was a opened dispute with the slashed agent\n        uint32 rivalIndex = 0;\n        if (agentDispute.disputePtr != 0) {\n            uint256 disputeIndex = agentDispute.disputePtr - 1;\n            OpenedDispute memory dispute = _disputes[disputeIndex];\n            _disputes[disputeIndex].slashedIndex = slashedIndex;\n            // Clear the dispute status for the rival\n            rivalIndex = dispute.notaryIndex == slashedIndex ? dispute.guardIndex : dispute.notaryIndex;\n            delete _agentDispute[rivalIndex];\n            emit DisputeResolved(disputeIndex, slashedIndex, rivalIndex, prover);\n        }\n        _notifyDisputeResolved(slashedIndex, rivalIndex);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Generates leaf to be saved in the Agent Merkle Tree\n    function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(flag, domain, agent));\n    }\n\n    /// @dev Returns the last known status for the agent from the Agent Merkle Tree.\n    /// Note: the actual agent status (returned by `agentStatus()`) may differ, if agent fraud was proven.\n    function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes.\n    function _getAgent(uint256 index) internal view virtual returns (address);\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.\n    function _getIndex(address agent) internal view virtual returns (uint256);\n}\n\n// contracts/manager/LightManager.sol\n\n// ══════════════════════════════ LIBRARY IMPORTS ══════════════════════════════\n\n// ═════════════════════════════ INTERNAL IMPORTS ══════════════════════════════\n\n/// @notice LightManager keeps track of all agents on chains other than Synapse Chain.\n/// Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the `BondingManager`.\n/// `LightManager` is responsible for the following:\n/// - Accepting the Agent Merkle Roots (passing the optimistic period check) from the `Destination` contract.\n/// - Using these roots to enable agents to register themselves by proving their status.\n/// - Accepting Manager Message from `BondingManager` on Synapse Chain to withdraw tips.\n/// - Sending Manager Messages to `BondingManager` on Synapse Chain to slash agents, when their fraud is proven.\ncontract LightManager is AgentManager, InterfaceLightManager {\n    // ══════════════════════════════════════════════════ STORAGE ══════════════════════════════════════════════════════\n    /// @inheritdoc IAgentManager\n    bytes32 public agentRoot;\n\n    /// @dev Pending Agent Merkle Root that was proposed by the contract owner.\n    bytes32 internal _proposedAgentRoot;\n\n    /// @dev Timestamp when the Agent Merkle Root was proposed by the contract owner.\n    uint256 internal _agentRootProposedAt;\n\n    // (agentRoot =\u003e (agent =\u003e status))\n    mapping(bytes32 =\u003e mapping(address =\u003e AgentStatus)) private _agentMap;\n\n    // (index =\u003e agent)\n    mapping(uint256 =\u003e address) private _agents;\n\n    // (agent =\u003e index)\n    mapping(address =\u003e uint256) private _agentIndexes;\n\n    // ═════════════════════════════════════════ CONSTRUCTOR \u0026 INITIALIZER ═════════════════════════════════════════════\n\n    constructor(uint32 synapseDomain_) MessagingBase(\"0.0.3\", synapseDomain_) {\n        if (localDomain == synapseDomain_) revert SynapseDomainForbidden();\n    }\n\n    function initialize(address origin_, address destination_, address inbox_) external initializer {\n        __AgentManager_init(origin_, destination_, inbox_);\n        __Ownable2Step_init();\n    }\n\n    // ════════════════════════════════════════════════ OWNER ONLY ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck {\n        if (agentRoot_ == 0) revert IncorrectAgentRoot();\n        // Update the proposed agent root, clear the timer if the root is empty\n        _proposedAgentRoot = agentRoot_;\n        _agentRootProposedAt = block.timestamp;\n        emit AgentRootProposed(agentRoot_);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function cancelProposedAgentRoot() external onlyOwner {\n        bytes32 cancelledAgentRoot = _proposedAgentRoot;\n        if (cancelledAgentRoot == 0) revert AgentRootNotProposed();\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootCancelled(cancelledAgentRoot);\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    /// @dev Should proceed with the proposed root, even if new Notary data is available.\n    /// This is done to prevent rogue Notaries from going offline and then\n    /// indefinitely blocking the agent root resolution, thus `onlyWhenStuck` modifier is not used here.\n    function resolveProposedAgentRoot() external onlyOwner {\n        bytes32 newAgentRoot = _proposedAgentRoot;\n        if (newAgentRoot == 0) revert AgentRootNotProposed();\n        if (block.timestamp \u003c _agentRootProposedAt + AGENT_ROOT_PROPOSAL_TIMEOUT) revert AgentRootTimeoutNotOver();\n        _setAgentRoot(newAgentRoot);\n        _proposedAgentRoot = 0;\n        _agentRootProposedAt = 0;\n        emit ProposedAgentRootResolved(newAgentRoot);\n    }\n\n    // ═══════════════════════════════════════════════ AGENTS LOGIC ════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external {\n        address storedAgent = _agents[status.index];\n        if (storedAgent != address(0) \u0026\u0026 storedAgent != agent) revert IncorrectAgentIndex();\n        // Reconstruct the agent leaf: flag should be Active\n        bytes32 leaf = _agentLeaf(status.flag, status.domain, agent);\n        bytes32 root = agentRoot;\n        // Check that proof matches the latest merkle root\n        if (MerkleMath.proofRoot(status.index, leaf, proof, AGENT_TREE_HEIGHT) != root) revert IncorrectAgentProof();\n        // Save index =\u003e agent in the map\n        if (storedAgent == address(0)) {\n            _agents[status.index] = agent;\n            _agentIndexes[agent] = status.index;\n        }\n        // Update the agent status against this root\n        _agentMap[root][agent] = status;\n        emit StatusUpdated(status.flag, status.domain, agent);\n        // Notify local AgentSecured contracts, if agent flag is Slashed\n        if (status.flag == AgentFlag.Slashed) {\n            // This will revert if the agent has been slashed earlier\n            _resolveDispute(status.index, msg.sender);\n        }\n    }\n\n    /// @inheritdoc InterfaceLightManager\n    function setAgentRoot(bytes32 agentRoot_) external {\n        // Only destination can pass AgentRoot to be set\n        if (msg.sender != destination) revert CallerNotDestination();\n        _setAgentRoot(agentRoot_);\n    }\n\n    // ════════════════════════════════════════════════ TIPS LOGIC ═════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)\n        external\n        returns (bytes4 magicValue)\n    {\n        // Only destination can pass Manager Messages\n        if (msg.sender != destination) revert CallerNotDestination();\n        // Only AgentManager on Synapse Chain can give instructions to withdraw tips\n        if (msgOrigin != synapseDomain) revert MustBeSynapseDomain();\n        // Check that merkle proof is mature enough\n        // TODO: separate constant for withdrawing tips optimistic period\n        if (proofMaturity \u003c BONDING_OPTIMISTIC_PERIOD) revert WithdrawTipsOptimisticPeriod();\n        InterfaceOrigin(origin).withdrawTips(recipient, amount);\n        // Magic value to return is selector of the called function\n        return this.remoteWithdrawTips.selector;\n    }\n\n    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════\n\n    /// @inheritdoc InterfaceLightManager\n    function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_) {\n        return (_proposedAgentRoot, _agentRootProposedAt);\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL LOGIC ═══════════════════════════════════════════════════\n\n    function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override {\n        // Send a manager message to BondingManager on SynChain\n        // remoteSlashAgent(msgOrigin, proofMaturity, domain, agent, prover) with the first two security args omitted\n        InterfaceOrigin(origin).sendManagerMessage({\n            destination: synapseDomain,\n            optimisticPeriod: BONDING_OPTIMISTIC_PERIOD,\n            payload: abi.encodeWithSelector(InterfaceBondingManager.remoteSlashAgent.selector, domain, agent, prover)\n        });\n    }\n\n    /// @dev Notify local AgentSecured contracts about the opened dispute.\n    function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).openDispute(guardIndex, notaryIndex);\n    }\n\n    /// @dev Notify local AgentSecured contracts about the resolved dispute.\n    function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override {\n        // Origin contract doesn't need to know about the dispute\n        IAgentSecured(destination).resolveDispute(slashedIndex, rivalIndex);\n    }\n\n    /// @dev Updates the Agent Merkle Root that Light Manager is tracking.\n    function _setAgentRoot(bytes32 _agentRoot) internal {\n        if (agentRoot != _agentRoot) {\n            agentRoot = _agentRoot;\n            emit RootUpdated(_agentRoot);\n        }\n    }\n\n    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════\n\n    /// @dev Returns the stored status for the agent: whether or not they have been added\n    /// using latest Agent merkle Root.\n    function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory) {\n        return _agentMap[agentRoot][agent];\n    }\n\n    /// @dev Returns agent address for the given index. Returns zero for non existing indexes, or for indexes\n    /// of the agents that have not been added to Light Manager yet.\n    function _getAgent(uint256 index) internal view override returns (address agent) {\n        return _agents[index];\n    }\n\n    /// @dev Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or\n    /// for agents that have not been added to Light Manager yet.\n    function _getIndex(address agent) internal view override returns (uint256 index) {\n        return _agentIndexes[agent];\n    }\n}\n","language":"Solidity","languageVersion":"0.8.17","compilerVersion":"0.8.17","compilerOptions":"--combined-json bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata,hashes --optimize --optimize-runs 10000 --allow-paths ., ./, ../","srcMap":"","srcMapRuntime":"","abiDefinition":[{"inputs":[],"name":"IncorrectVersionLength","type":"error"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"versionString","type":"string"}],"stateMutability":"view","type":"function"}],"userDoc":{"kind":"user","methods":{},"notice":"Version getter for contracts. Doesn't use any storage slots, meaning it will never cause any troubles with the upgradeable contracts. For instance, this contract can be added or removed from the inheritance chain without shifting the storage layout.","version":1},"developerDoc":{"kind":"dev","methods":{},"stateVariables":{"_data":{"details":"Bytes representation of the \"version string\". Strings with length over 32 are not supported!"},"_length":{"details":"Length of the \"version string\""}},"title":"Versioned","version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"IncorrectVersionLength\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"versionString\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"stateVariables\":{\"_data\":{\"details\":\"Bytes representation of the \\\"version string\\\". Strings with length over 32 are not supported!\"},\"_length\":{\"details\":\"Length of the \\\"version string\\\"\"}},\"title\":\"Versioned\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"notice\":\"Version getter for contracts. Doesn't use any storage slots, meaning it will never cause any troubles with the upgradeable contracts. For instance, this contract can be added or removed from the inheritance chain without shifting the storage layout.\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/LightManager.sol\":\"Versioned\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/LightManager.sol\":{\"keccak256\":\"0xcb557c1a95bcb43e98bd6f58c18e5c7bf086167de12e7378a2c1c331cc40b232\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://48e326a81aba436e4b6a8323be3ce534c2e4ce6a5bb0f10424c7df61441cff0a\",\"dweb:/ipfs/QmdaV2u5dmEMLNtG1xd3pU9n7CBJbPqL5sz4s2Qvse1SYq\"]}},\"version\":1}"},"hashes":{"version()":"54fd4d50"}}}