agents/contracts/test/stateharness/stateharness.contractinfo.json
{"solidity/StateHarness.t.sol:GasDataLib":{"code":"0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea264697066735822122098e4766b0c8323dc9de6561a9ef987b4b0d0431b8d58bbf5c74410d74941508b64736f6c63430008110033","runtime-code":"0x73000000000000000000000000000000000000000030146080604052600080fdfea264697066735822122098e4766b0c8323dc9de6561a9ef987b4b0d0431b8d58bbf5c74410d74941508b64736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17;\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// contracts/libs/memory/MemView.sol\n\n/// @dev MemView is an untyped view over a portion of memory to be used instead of `bytes memory`\ntype MemView is uint256;\n\n/// @dev Attach library functions to MemView\nusing MemViewLib for MemView global;\n\n/// @notice Library for operations with the memory views.\n/// Forked from https://github.com/summa-tx/memview-sol with several breaking changes:\n/// - The codebase is ported to Solidity 0.8\n/// - Custom errors are added\n/// - The runtime type checking is replaced with compile-time check provided by User-Defined Value Types\n/// https://docs.soliditylang.org/en/latest/types.html#user-defined-value-types\n/// - uint256 is used as the underlying type for the \"memory view\" instead of bytes29.\n/// It is wrapped into MemView custom type in order not to be confused with actual integers.\n/// - Therefore the \"type\" field is discarded, allowing to allocate 16 bytes for both view location and length\n/// - The documentation is expanded\n/// - Library functions unused by the rest of the codebase are removed\n// - Very pretty code separators are added :)\nlibrary MemViewLib {\n /// @notice Stack layout for uint256 (from highest bits to lowest)\n /// (32 .. 16] loc 16 bytes Memory address of underlying bytes\n /// (16 .. 00] len 16 bytes Length of underlying bytes\n\n // ═══════════════════════════════════════════ BUILDING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Instantiate a new untyped memory view. This should generally not be called directly.\n * Prefer `ref` wherever possible.\n * @param loc_ The memory address\n * @param len_ The length\n * @return The new view with the specified location and length\n */\n function build(uint256 loc_, uint256 len_) internal pure returns (MemView) {\n uint256 end_ = loc_ + len_;\n // Make sure that a view is not constructed that points to unallocated memory\n // as this could be indicative of a buffer overflow attack\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n if gt(end_, mload(0x40)) { end_ := 0 }\n }\n if (end_ == 0) {\n revert UnallocatedMemory();\n }\n return _unsafeBuildUnchecked(loc_, len_);\n }\n\n /**\n * @notice Instantiate a memory view from a byte array.\n * @dev Note that due to Solidity memory representation, it is not possible to\n * implement a deref, as the `bytes` type stores its len in memory.\n * @param arr The byte array\n * @return The memory view over the provided byte array\n */\n function ref(bytes memory arr) internal pure returns (MemView) {\n uint256 len_ = arr.length;\n // `bytes arr` is stored in memory in the following way\n // 1. First, uint256 arr.length is stored. That requires 32 bytes (0x20).\n // 2. Then, the array data is stored.\n uint256 loc_;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // We add 0x20, so that the view starts exactly where the array data starts\n loc_ := add(arr, 0x20)\n }\n return build(loc_, len_);\n }\n\n // ════════════════════════════════════════════ CLONING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Copies the referenced memory to a new loc in memory, returning a `bytes` pointing to the new memory.\n * @param memView The memory view\n * @return arr The cloned byte array\n */\n function clone(MemView memView) internal view returns (bytes memory arr) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n // This is where the byte array will be stored\n arr := ptr\n }\n unchecked {\n _unsafeCopyTo(memView, ptr + 0x20);\n }\n // `bytes arr` is stored in memory in the following way\n // 1. First, uint256 arr.length is stored. That requires 32 bytes (0x20).\n // 2. Then, the array data is stored.\n uint256 len_ = memView.len();\n uint256 footprint_ = memView.footprint();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Write new unused pointer: the old value + array footprint + 32 bytes to store the length\n mstore(0x40, add(add(ptr, footprint_), 0x20))\n // Write len of new array (in bytes)\n mstore(ptr, len_)\n }\n }\n\n /**\n * @notice Copies all views, joins them into a new bytearray.\n * @param memViews The memory views\n * @return arr The new byte array with joined data behind the given views\n */\n function join(MemView[] memory memViews) internal view returns (bytes memory arr) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n // This is where the byte array will be stored\n arr := ptr\n }\n MemView newView;\n unchecked {\n newView = _unsafeJoin(memViews, ptr + 0x20);\n }\n uint256 len_ = newView.len();\n uint256 footprint_ = newView.footprint();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Write new unused pointer: the old value + array footprint + 32 bytes to store the length\n mstore(0x40, add(add(ptr, footprint_), 0x20))\n // Write len of new array (in bytes)\n mstore(ptr, len_)\n }\n }\n\n // ══════════════════════════════════════════ INSPECTING MEMORY VIEW ═══════════════════════════════════════════════\n\n /**\n * @notice Returns the memory address of the underlying bytes.\n * @param memView The memory view\n * @return loc_ The memory address\n */\n function loc(MemView memView) internal pure returns (uint256 loc_) {\n // loc is stored in the highest 16 bytes of the underlying uint256\n return MemView.unwrap(memView) \u003e\u003e 128;\n }\n\n /**\n * @notice Returns the number of bytes of the view.\n * @param memView The memory view\n * @return len_ The length of the view\n */\n function len(MemView memView) internal pure returns (uint256 len_) {\n // len is stored in the lowest 16 bytes of the underlying uint256\n return MemView.unwrap(memView) \u0026 type(uint128).max;\n }\n\n /**\n * @notice Returns the endpoint of `memView`.\n * @param memView The memory view\n * @return end_ The endpoint of `memView`\n */\n function end(MemView memView) internal pure returns (uint256 end_) {\n // The endpoint never overflows uint128, let alone uint256, so we could use unchecked math here\n unchecked {\n return memView.loc() + memView.len();\n }\n }\n\n /**\n * @notice Returns the number of memory words this memory view occupies, rounded up.\n * @param memView The memory view\n * @return words_ The number of memory words\n */\n function words(MemView memView) internal pure returns (uint256 words_) {\n // returning ceil(length / 32.0)\n unchecked {\n return (memView.len() + 31) \u003e\u003e 5;\n }\n }\n\n /**\n * @notice Returns the in-memory footprint of a fresh copy of the view.\n * @param memView The memory view\n * @return footprint_ The in-memory footprint of a fresh copy of the view.\n */\n function footprint(MemView memView) internal pure returns (uint256 footprint_) {\n // words() * 32\n return memView.words() \u003c\u003c 5;\n }\n\n // ════════════════════════════════════════════ HASHING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Returns the keccak256 hash of the underlying memory\n * @param memView The memory view\n * @return digest The keccak256 hash of the underlying memory\n */\n function keccak(MemView memView) internal pure returns (bytes32 digest) {\n uint256 loc_ = memView.loc();\n uint256 len_ = memView.len();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n digest := keccak256(loc_, len_)\n }\n }\n\n /**\n * @notice Adds a salt to the keccak256 hash of the underlying data and returns the keccak256 hash of the\n * resulting data.\n * @param memView The memory view\n * @return digestSalted keccak256(salt, keccak256(memView))\n */\n function keccakSalted(MemView memView, bytes32 salt) internal pure returns (bytes32 digestSalted) {\n return keccak256(bytes.concat(salt, memView.keccak()));\n }\n\n // ════════════════════════════════════════════ SLICING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Safe slicing without memory modification.\n * @param memView The memory view\n * @param index_ The start index\n * @param len_ The length\n * @return The new view for the slice of the given length starting from the given index\n */\n function slice(MemView memView, uint256 index_, uint256 len_) internal pure returns (MemView) {\n uint256 loc_ = memView.loc();\n // Ensure it doesn't overrun the view\n if (loc_ + index_ + len_ \u003e memView.end()) {\n revert ViewOverrun();\n }\n // Build a view starting from index with the given length\n unchecked {\n // loc_ + index_ \u003c= memView.end()\n return build({loc_: loc_ + index_, len_: len_});\n }\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing bytes from `index` to end(memView).\n * @param memView The memory view\n * @param index_ The start index\n * @return The new view for the slice starting from the given index until the initial view endpoint\n */\n function sliceFrom(MemView memView, uint256 index_) internal pure returns (MemView) {\n uint256 len_ = memView.len();\n // Ensure it doesn't overrun the view\n if (index_ \u003e len_) {\n revert ViewOverrun();\n }\n // Build a view starting from index with the given length\n unchecked {\n // index_ \u003c= len_ =\u003e memView.loc() + index_ \u003c= memView.loc() + memView.len() == memView.end()\n return build({loc_: memView.loc() + index_, len_: len_ - index_});\n }\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing the first `len` bytes.\n * @param memView The memory view\n * @param len_ The length\n * @return The new view for the slice of the given length starting from the initial view beginning\n */\n function prefix(MemView memView, uint256 len_) internal pure returns (MemView) {\n return memView.slice({index_: 0, len_: len_});\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing the last `len` byte.\n * @param memView The memory view\n * @param len_ The length\n * @return The new view for the slice of the given length until the initial view endpoint\n */\n function postfix(MemView memView, uint256 len_) internal pure returns (MemView) {\n uint256 viewLen = memView.len();\n // Ensure it doesn't overrun the view\n if (len_ \u003e viewLen) {\n revert ViewOverrun();\n }\n // Could do the unchecked math due to the check above\n uint256 index_;\n unchecked {\n index_ = viewLen - len_;\n }\n // Build a view starting from index with the given length\n unchecked {\n // len_ \u003c= memView.len() =\u003e memView.loc() \u003c= loc_ \u003c= memView.end()\n return build({loc_: memView.loc() + viewLen - len_, len_: len_});\n }\n }\n\n // ═══════════════════════════════════════════ INDEXING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Load up to 32 bytes from the view onto the stack.\n * @dev Returns a bytes32 with only the `bytes_` HIGHEST bytes set.\n * This can be immediately cast to a smaller fixed-length byte array.\n * To automatically cast to an integer, use `indexUint`.\n * @param memView The memory view\n * @param index_ The index\n * @param bytes_ The amount of bytes to load onto the stack\n * @return result The 32 byte result having only `bytes_` highest bytes set\n */\n function index(MemView memView, uint256 index_, uint256 bytes_) internal pure returns (bytes32 result) {\n if (bytes_ == 0) {\n return bytes32(0);\n }\n // Can't load more than 32 bytes to the stack in one go\n if (bytes_ \u003e 32) {\n revert IndexedTooMuch();\n }\n // The last indexed byte should be within view boundaries\n if (index_ + bytes_ \u003e memView.len()) {\n revert ViewOverrun();\n }\n uint256 bitLength = bytes_ \u003c\u003c 3; // bytes_ * 8\n uint256 loc_ = memView.loc();\n // Get a mask with `bitLength` highest bits set\n uint256 mask;\n // 0x800...00 binary representation is 100...00\n // sar stands for \"signed arithmetic shift\": https://en.wikipedia.org/wiki/Arithmetic_shift\n // sar(N-1, 100...00) = 11...100..00, with exactly N highest bits set to 1\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n mask := sar(sub(bitLength, 1), 0x8000000000000000000000000000000000000000000000000000000000000000)\n }\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load a full word using index offset, and apply mask to ignore non-relevant bytes\n result := and(mload(add(loc_, index_)), mask)\n }\n }\n\n /**\n * @notice Parse an unsigned integer from the view at `index`.\n * @dev Requires that the view have \u003e= `bytes_` bytes following that index.\n * @param memView The memory view\n * @param index_ The index\n * @param bytes_ The amount of bytes to load onto the stack\n * @return The unsigned integer\n */\n function indexUint(MemView memView, uint256 index_, uint256 bytes_) internal pure returns (uint256) {\n bytes32 indexedBytes = memView.index(index_, bytes_);\n // `index()` returns left-aligned `bytes_`, while integers are right-aligned\n // Shifting here to right-align with the full 32 bytes word: need to shift right `(32 - bytes_)` bytes\n unchecked {\n // memView.index() reverts when bytes_ \u003e 32, thus unchecked math\n return uint256(indexedBytes) \u003e\u003e ((32 - bytes_) \u003c\u003c 3);\n }\n }\n\n /**\n * @notice Parse an address from the view at `index`.\n * @dev Requires that the view have \u003e= 20 bytes following that index.\n * @param memView The memory view\n * @param index_ The index\n * @return The address\n */\n function indexAddress(MemView memView, uint256 index_) internal pure returns (address) {\n // index 20 bytes as `uint160`, and then cast to `address`\n return address(uint160(memView.indexUint(index_, 20)));\n }\n\n // ══════════════════════════════════════════════ PRIVATE HELPERS ══════════════════════════════════════════════════\n\n /// @dev Returns a memory view over the specified memory location\n /// without checking if it points to unallocated memory.\n function _unsafeBuildUnchecked(uint256 loc_, uint256 len_) private pure returns (MemView) {\n // There is no scenario where loc or len would overflow uint128, so we omit this check.\n // We use the highest 128 bits to encode the location and the lowest 128 bits to encode the length.\n return MemView.wrap((loc_ \u003c\u003c 128) | len_);\n }\n\n /**\n * @notice Copy the view to a location, return an unsafe memory reference\n * @dev Super Dangerous direct memory access.\n * This reference can be overwritten if anything else modifies memory (!!!).\n * As such it MUST be consumed IMMEDIATELY. Update the free memory pointer to ensure the copied data\n * is not overwritten. This function is private to prevent unsafe usage by callers.\n * @param memView The memory view\n * @param newLoc The new location to copy the underlying view data\n * @return The memory view over the unsafe memory with the copied underlying data\n */\n function _unsafeCopyTo(MemView memView, uint256 newLoc) private view returns (MemView) {\n uint256 len_ = memView.len();\n uint256 oldLoc = memView.loc();\n\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n }\n // Revert if we're writing in occupied memory\n if (newLoc \u003c ptr) {\n revert OccupiedMemory();\n }\n bool res;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // use the identity precompile (0x04) to copy\n res := staticcall(gas(), 0x04, oldLoc, len_, newLoc, len_)\n }\n if (!res) revert PrecompileOutOfGas();\n return _unsafeBuildUnchecked({loc_: newLoc, len_: len_});\n }\n\n /**\n * @notice Join the views in memory, return an unsafe reference to the memory.\n * @dev Super Dangerous direct memory access.\n * This reference can be overwritten if anything else modifies memory (!!!).\n * As such it MUST be consumed IMMEDIATELY. Update the free memory pointer to ensure the copied data\n * is not overwritten. This function is private to prevent unsafe usage by callers.\n * @param memViews The memory views\n * @return The conjoined view pointing to the new memory\n */\n function _unsafeJoin(MemView[] memory memViews, uint256 location) private view returns (MemView) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n }\n // Revert if we're writing in occupied memory\n if (location \u003c ptr) {\n revert OccupiedMemory();\n }\n // Copy the views to the specified location one by one, by tracking the amount of copied bytes so far\n uint256 offset = 0;\n for (uint256 i = 0; i \u003c memViews.length;) {\n MemView memView = memViews[i];\n // We can use the unchecked math here as location + sum(view.length) will never overflow uint256\n unchecked {\n _unsafeCopyTo(memView, location + offset);\n offset += memView.len();\n ++i;\n }\n }\n return _unsafeBuildUnchecked({loc_: location, len_: offset});\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// contracts/libs/memory/State.sol\n\n/// State is a memory view over a formatted state payload.\ntype State is uint256;\n\nusing StateLib for State global;\n\n/// # State\n/// State structure represents the state of Origin contract at some point of time.\n/// - State is structured in a way to track the updates of the Origin Merkle Tree.\n/// - State includes root of the Origin Merkle Tree, origin domain and some additional metadata.\n/// ## Origin Merkle Tree\n/// Hash of every sent message is inserted in the Origin Merkle Tree, which changes\n/// the value of Origin Merkle Root (which is the root for the mentioned tree).\n/// - Origin has a single Merkle Tree for all messages, regardless of their destination domain.\n/// - This leads to Origin state being updated if and only if a message was sent in a block.\n/// - Origin contract is a \"source of truth\" for states: a state is considered \"valid\" in its Origin,\n/// if it matches the state of the Origin contract after the N-th (nonce) message was sent.\n///\n/// # Memory layout of State fields\n///\n/// | Position | Field | Type | Bytes | Description |\n/// | ---------- | ----------- | ------- | ----- | ------------------------------ |\n/// | [000..032) | root | bytes32 | 32 | Root of the Origin Merkle Tree |\n/// | [032..036) | origin | uint32 | 4 | Domain where Origin is located |\n/// | [036..040) | nonce | uint32 | 4 | Amount of sent messages |\n/// | [040..045) | blockNumber | uint40 | 5 | Block of last sent message |\n/// | [045..050) | timestamp | uint40 | 5 | Time of last sent message |\n/// | [050..062) | gasData | uint96 | 12 | Gas data for the chain |\n///\n/// @dev State could be used to form a Snapshot to be signed by a Guard or a Notary.\nlibrary StateLib {\n using MemViewLib for bytes;\n\n /// @dev The variables below are not supposed to be used outside of the library directly.\n uint256 private constant OFFSET_ROOT = 0;\n uint256 private constant OFFSET_ORIGIN = 32;\n uint256 private constant OFFSET_NONCE = 36;\n uint256 private constant OFFSET_BLOCK_NUMBER = 40;\n uint256 private constant OFFSET_TIMESTAMP = 45;\n uint256 private constant OFFSET_GAS_DATA = 50;\n\n // ═══════════════════════════════════════════════════ STATE ═══════════════════════════════════════════════════════\n\n /**\n * @notice Returns a formatted State payload with provided fields\n * @param root_ New merkle root\n * @param origin_ Domain of Origin's chain\n * @param nonce_ Nonce of the merkle root\n * @param blockNumber_ Block number when root was saved in Origin\n * @param timestamp_ Block timestamp when root was saved in Origin\n * @param gasData_ Gas data for the chain\n * @return Formatted state\n */\n function formatState(\n bytes32 root_,\n uint32 origin_,\n uint32 nonce_,\n uint40 blockNumber_,\n uint40 timestamp_,\n GasData gasData_\n ) internal pure returns (bytes memory) {\n return abi.encodePacked(root_, origin_, nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n /**\n * @notice Returns a State view over the given payload.\n * @dev Will revert if the payload is not a state.\n */\n function castToState(bytes memory payload) internal pure returns (State) {\n return castToState(payload.ref());\n }\n\n /**\n * @notice Casts a memory view to a State view.\n * @dev Will revert if the memory view is not over a state.\n */\n function castToState(MemView memView) internal pure returns (State) {\n if (!isState(memView)) revert UnformattedState();\n return State.wrap(MemView.unwrap(memView));\n }\n\n /// @notice Checks that a payload is a formatted State.\n function isState(MemView memView) internal pure returns (bool) {\n return memView.len() == STATE_LENGTH;\n }\n\n /// @notice Returns the hash of a State, that could be later signed by a Guard to signal\n /// that the state is invalid.\n function hashInvalid(State state) internal pure returns (bytes32) {\n // The final hash to sign is keccak(stateInvalidSalt, keccak(state))\n return state.unwrap().keccakSalted(STATE_INVALID_SALT);\n }\n\n /// @notice Convenience shortcut for unwrapping a view.\n function unwrap(State state) internal pure returns (MemView) {\n return MemView.wrap(State.unwrap(state));\n }\n\n /// @notice Compares two State structures.\n function equals(State a, State b) internal pure returns (bool) {\n // Length of a State payload is fixed, so we just need to compare the hashes\n return a.unwrap().keccak() == b.unwrap().keccak();\n }\n\n // ═══════════════════════════════════════════════ STATE HASHING ═══════════════════════════════════════════════════\n\n /// @notice Returns the hash of the State.\n /// @dev We are using the Merkle Root of a tree with two leafs (see below) as state hash.\n function leaf(State state) internal pure returns (bytes32) {\n (bytes32 leftLeaf_, bytes32 rightLeaf_) = state.subLeafs();\n // Final hash is the parent of these leafs\n return keccak256(bytes.concat(leftLeaf_, rightLeaf_));\n }\n\n /// @notice Returns \"sub-leafs\" of the State. Hash of these \"sub leafs\" is going to be used\n /// as a \"state leaf\" in the \"Snapshot Merkle Tree\".\n /// This enables proving that leftLeaf = (root, origin) was a part of the \"Snapshot Merkle Tree\",\n /// by combining `rightLeaf` with the remainder of the \"Snapshot Merkle Proof\".\n function subLeafs(State state) internal pure returns (bytes32 leftLeaf_, bytes32 rightLeaf_) {\n MemView memView = state.unwrap();\n // Left leaf is (root, origin)\n leftLeaf_ = memView.prefix({len_: OFFSET_NONCE}).keccak();\n // Right leaf is (metadata), or (nonce, blockNumber, timestamp)\n rightLeaf_ = memView.sliceFrom({index_: OFFSET_NONCE}).keccak();\n }\n\n /// @notice Returns the left \"sub-leaf\" of the State.\n function leftLeaf(bytes32 root_, uint32 origin_) internal pure returns (bytes32) {\n // We use encodePacked here to simulate the State memory layout\n return keccak256(abi.encodePacked(root_, origin_));\n }\n\n /// @notice Returns the right \"sub-leaf\" of the State.\n function rightLeaf(uint32 nonce_, uint40 blockNumber_, uint40 timestamp_, GasData gasData_)\n internal\n pure\n returns (bytes32)\n {\n // We use encodePacked here to simulate the State memory layout\n return keccak256(abi.encodePacked(nonce_, blockNumber_, timestamp_, gasData_));\n }\n\n // ═══════════════════════════════════════════════ STATE SLICING ═══════════════════════════════════════════════════\n\n /// @notice Returns a historical Merkle root from the Origin contract.\n function root(State state) internal pure returns (bytes32) {\n return state.unwrap().index({index_: OFFSET_ROOT, bytes_: 32});\n }\n\n /// @notice Returns domain of chain where the Origin contract is deployed.\n function origin(State state) internal pure returns (uint32) {\n // Can be safely casted to uint32, since we index 4 bytes\n return uint32(state.unwrap().indexUint({index_: OFFSET_ORIGIN, bytes_: 4}));\n }\n\n /// @notice Returns nonce of Origin contract at the time, when `root` was the Merkle root.\n function nonce(State state) internal pure returns (uint32) {\n // Can be safely casted to uint32, since we index 4 bytes\n return uint32(state.unwrap().indexUint({index_: OFFSET_NONCE, bytes_: 4}));\n }\n\n /// @notice Returns a block number when `root` was saved in Origin.\n function blockNumber(State state) internal pure returns (uint40) {\n // Can be safely casted to uint40, since we index 5 bytes\n return uint40(state.unwrap().indexUint({index_: OFFSET_BLOCK_NUMBER, bytes_: 5}));\n }\n\n /// @notice Returns a block timestamp when `root` was saved in Origin.\n /// @dev This is the timestamp according to the origin chain.\n function timestamp(State state) internal pure returns (uint40) {\n // Can be safely casted to uint40, since we index 5 bytes\n return uint40(state.unwrap().indexUint({index_: OFFSET_TIMESTAMP, bytes_: 5}));\n }\n\n /// @notice Returns gas data for the chain.\n function gasData(State state) internal pure returns (GasData) {\n return GasDataLib.wrapGasData(state.unwrap().indexUint({index_: OFFSET_GAS_DATA, bytes_: GAS_DATA_LENGTH}));\n }\n}\n\n// test/harnesses/libs/memory/StateHarness.t.sol\n\n// solhint-disable ordering\n/// @notice Exposes State methods for testing against golang.\ncontract StateHarness {\n using StateLib for bytes;\n using StateLib for MemView;\n using MemViewLib for bytes;\n\n // Note: we don't add an empty test() function here, as it currently leads\n // to zero coverage on the corresponding library.\n\n // ══════════════════════════════════════════════════ GETTERS ══════════════════════════════════════════════════════\n\n function castToState(bytes memory payload) public view returns (bytes memory) {\n // Walkaround to get the forge coverage working on libraries, see\n // https://github.com/foundry-rs/foundry/pull/3128#issuecomment-1241245086\n State state = StateLib.castToState(payload);\n return state.unwrap().clone();\n }\n\n function equals(bytes memory a, bytes memory b) public pure returns (bool) {\n return a.castToState().equals(b.castToState());\n }\n\n function hashInvalid(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().hashInvalid();\n }\n\n function leaf(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().leaf();\n }\n\n function subLeafs(bytes memory payload) public pure returns (bytes32, bytes32) {\n return payload.castToState().subLeafs();\n }\n\n function leftLeaf(bytes32 root_, uint32 origin_) public pure returns (bytes32) {\n return StateLib.leftLeaf(root_, origin_);\n }\n\n function rightLeaf(uint32 nonce_, uint40 blockNumber_, uint40 timestamp_, GasData gasData_)\n public\n pure\n returns (bytes32)\n {\n return StateLib.rightLeaf(nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n function root(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().root();\n }\n\n function origin(bytes memory payload) public pure returns (uint32) {\n return payload.castToState().origin();\n }\n\n function nonce(bytes memory payload) public pure returns (uint32) {\n return payload.castToState().nonce();\n }\n\n function blockNumber(bytes memory payload) public pure returns (uint40) {\n return payload.castToState().blockNumber();\n }\n\n function timestamp(bytes memory payload) public pure returns (uint40) {\n return payload.castToState().timestamp();\n }\n\n function gasData(bytes memory payload) public pure returns (GasData) {\n return payload.castToState().gasData();\n }\n\n // ════════════════════════════════════════════════ FORMATTERS ═════════════════════════════════════════════════════\n\n function formatState(\n bytes32 root_,\n uint32 origin_,\n uint32 nonce_,\n uint40 blockNumber_,\n uint40 timestamp_,\n GasData gasData_\n ) public pure returns (bytes memory) {\n return StateLib.formatState(root_, origin_, nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n function isState(bytes memory payload) public pure returns (bool) {\n return payload.ref().isState();\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":"37371:7222:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;37371:7222:0;;;;;;;;;;;;;;;;;","srcMapRuntime":"37371: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/StateHarness.t.sol\":\"GasDataLib\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/StateHarness.t.sol\":{\"keccak256\":\"0x18cffce3039e8ab774b0011a4bbf9812533e064bdfebfe70b931ec2427614089\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://d1081451a985d6522077ce9dd2bf81a2d3f726e1003a3b588240ed416968ee36\",\"dweb:/ipfs/QmPmWLB1F2KzmCwmr1KTwFbPtHnE11Axr386vjrBc4aWM9\"]}},\"version\":1}"},"hashes":{}},"solidity/StateHarness.t.sol:MemViewLib":{"code":"0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220b75550cc7ace0c84999dab51372dbe380730c824832578a7368e4ff1c49eb2e964736f6c63430008110033","runtime-code":"0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220b75550cc7ace0c84999dab51372dbe380730c824832578a7368e4ff1c49eb2e964736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17;\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// contracts/libs/memory/MemView.sol\n\n/// @dev MemView is an untyped view over a portion of memory to be used instead of `bytes memory`\ntype MemView is uint256;\n\n/// @dev Attach library functions to MemView\nusing MemViewLib for MemView global;\n\n/// @notice Library for operations with the memory views.\n/// Forked from https://github.com/summa-tx/memview-sol with several breaking changes:\n/// - The codebase is ported to Solidity 0.8\n/// - Custom errors are added\n/// - The runtime type checking is replaced with compile-time check provided by User-Defined Value Types\n/// https://docs.soliditylang.org/en/latest/types.html#user-defined-value-types\n/// - uint256 is used as the underlying type for the \"memory view\" instead of bytes29.\n/// It is wrapped into MemView custom type in order not to be confused with actual integers.\n/// - Therefore the \"type\" field is discarded, allowing to allocate 16 bytes for both view location and length\n/// - The documentation is expanded\n/// - Library functions unused by the rest of the codebase are removed\n// - Very pretty code separators are added :)\nlibrary MemViewLib {\n /// @notice Stack layout for uint256 (from highest bits to lowest)\n /// (32 .. 16] loc 16 bytes Memory address of underlying bytes\n /// (16 .. 00] len 16 bytes Length of underlying bytes\n\n // ═══════════════════════════════════════════ BUILDING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Instantiate a new untyped memory view. This should generally not be called directly.\n * Prefer `ref` wherever possible.\n * @param loc_ The memory address\n * @param len_ The length\n * @return The new view with the specified location and length\n */\n function build(uint256 loc_, uint256 len_) internal pure returns (MemView) {\n uint256 end_ = loc_ + len_;\n // Make sure that a view is not constructed that points to unallocated memory\n // as this could be indicative of a buffer overflow attack\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n if gt(end_, mload(0x40)) { end_ := 0 }\n }\n if (end_ == 0) {\n revert UnallocatedMemory();\n }\n return _unsafeBuildUnchecked(loc_, len_);\n }\n\n /**\n * @notice Instantiate a memory view from a byte array.\n * @dev Note that due to Solidity memory representation, it is not possible to\n * implement a deref, as the `bytes` type stores its len in memory.\n * @param arr The byte array\n * @return The memory view over the provided byte array\n */\n function ref(bytes memory arr) internal pure returns (MemView) {\n uint256 len_ = arr.length;\n // `bytes arr` is stored in memory in the following way\n // 1. First, uint256 arr.length is stored. That requires 32 bytes (0x20).\n // 2. Then, the array data is stored.\n uint256 loc_;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // We add 0x20, so that the view starts exactly where the array data starts\n loc_ := add(arr, 0x20)\n }\n return build(loc_, len_);\n }\n\n // ════════════════════════════════════════════ CLONING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Copies the referenced memory to a new loc in memory, returning a `bytes` pointing to the new memory.\n * @param memView The memory view\n * @return arr The cloned byte array\n */\n function clone(MemView memView) internal view returns (bytes memory arr) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n // This is where the byte array will be stored\n arr := ptr\n }\n unchecked {\n _unsafeCopyTo(memView, ptr + 0x20);\n }\n // `bytes arr` is stored in memory in the following way\n // 1. First, uint256 arr.length is stored. That requires 32 bytes (0x20).\n // 2. Then, the array data is stored.\n uint256 len_ = memView.len();\n uint256 footprint_ = memView.footprint();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Write new unused pointer: the old value + array footprint + 32 bytes to store the length\n mstore(0x40, add(add(ptr, footprint_), 0x20))\n // Write len of new array (in bytes)\n mstore(ptr, len_)\n }\n }\n\n /**\n * @notice Copies all views, joins them into a new bytearray.\n * @param memViews The memory views\n * @return arr The new byte array with joined data behind the given views\n */\n function join(MemView[] memory memViews) internal view returns (bytes memory arr) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n // This is where the byte array will be stored\n arr := ptr\n }\n MemView newView;\n unchecked {\n newView = _unsafeJoin(memViews, ptr + 0x20);\n }\n uint256 len_ = newView.len();\n uint256 footprint_ = newView.footprint();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Write new unused pointer: the old value + array footprint + 32 bytes to store the length\n mstore(0x40, add(add(ptr, footprint_), 0x20))\n // Write len of new array (in bytes)\n mstore(ptr, len_)\n }\n }\n\n // ══════════════════════════════════════════ INSPECTING MEMORY VIEW ═══════════════════════════════════════════════\n\n /**\n * @notice Returns the memory address of the underlying bytes.\n * @param memView The memory view\n * @return loc_ The memory address\n */\n function loc(MemView memView) internal pure returns (uint256 loc_) {\n // loc is stored in the highest 16 bytes of the underlying uint256\n return MemView.unwrap(memView) \u003e\u003e 128;\n }\n\n /**\n * @notice Returns the number of bytes of the view.\n * @param memView The memory view\n * @return len_ The length of the view\n */\n function len(MemView memView) internal pure returns (uint256 len_) {\n // len is stored in the lowest 16 bytes of the underlying uint256\n return MemView.unwrap(memView) \u0026 type(uint128).max;\n }\n\n /**\n * @notice Returns the endpoint of `memView`.\n * @param memView The memory view\n * @return end_ The endpoint of `memView`\n */\n function end(MemView memView) internal pure returns (uint256 end_) {\n // The endpoint never overflows uint128, let alone uint256, so we could use unchecked math here\n unchecked {\n return memView.loc() + memView.len();\n }\n }\n\n /**\n * @notice Returns the number of memory words this memory view occupies, rounded up.\n * @param memView The memory view\n * @return words_ The number of memory words\n */\n function words(MemView memView) internal pure returns (uint256 words_) {\n // returning ceil(length / 32.0)\n unchecked {\n return (memView.len() + 31) \u003e\u003e 5;\n }\n }\n\n /**\n * @notice Returns the in-memory footprint of a fresh copy of the view.\n * @param memView The memory view\n * @return footprint_ The in-memory footprint of a fresh copy of the view.\n */\n function footprint(MemView memView) internal pure returns (uint256 footprint_) {\n // words() * 32\n return memView.words() \u003c\u003c 5;\n }\n\n // ════════════════════════════════════════════ HASHING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Returns the keccak256 hash of the underlying memory\n * @param memView The memory view\n * @return digest The keccak256 hash of the underlying memory\n */\n function keccak(MemView memView) internal pure returns (bytes32 digest) {\n uint256 loc_ = memView.loc();\n uint256 len_ = memView.len();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n digest := keccak256(loc_, len_)\n }\n }\n\n /**\n * @notice Adds a salt to the keccak256 hash of the underlying data and returns the keccak256 hash of the\n * resulting data.\n * @param memView The memory view\n * @return digestSalted keccak256(salt, keccak256(memView))\n */\n function keccakSalted(MemView memView, bytes32 salt) internal pure returns (bytes32 digestSalted) {\n return keccak256(bytes.concat(salt, memView.keccak()));\n }\n\n // ════════════════════════════════════════════ SLICING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Safe slicing without memory modification.\n * @param memView The memory view\n * @param index_ The start index\n * @param len_ The length\n * @return The new view for the slice of the given length starting from the given index\n */\n function slice(MemView memView, uint256 index_, uint256 len_) internal pure returns (MemView) {\n uint256 loc_ = memView.loc();\n // Ensure it doesn't overrun the view\n if (loc_ + index_ + len_ \u003e memView.end()) {\n revert ViewOverrun();\n }\n // Build a view starting from index with the given length\n unchecked {\n // loc_ + index_ \u003c= memView.end()\n return build({loc_: loc_ + index_, len_: len_});\n }\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing bytes from `index` to end(memView).\n * @param memView The memory view\n * @param index_ The start index\n * @return The new view for the slice starting from the given index until the initial view endpoint\n */\n function sliceFrom(MemView memView, uint256 index_) internal pure returns (MemView) {\n uint256 len_ = memView.len();\n // Ensure it doesn't overrun the view\n if (index_ \u003e len_) {\n revert ViewOverrun();\n }\n // Build a view starting from index with the given length\n unchecked {\n // index_ \u003c= len_ =\u003e memView.loc() + index_ \u003c= memView.loc() + memView.len() == memView.end()\n return build({loc_: memView.loc() + index_, len_: len_ - index_});\n }\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing the first `len` bytes.\n * @param memView The memory view\n * @param len_ The length\n * @return The new view for the slice of the given length starting from the initial view beginning\n */\n function prefix(MemView memView, uint256 len_) internal pure returns (MemView) {\n return memView.slice({index_: 0, len_: len_});\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing the last `len` byte.\n * @param memView The memory view\n * @param len_ The length\n * @return The new view for the slice of the given length until the initial view endpoint\n */\n function postfix(MemView memView, uint256 len_) internal pure returns (MemView) {\n uint256 viewLen = memView.len();\n // Ensure it doesn't overrun the view\n if (len_ \u003e viewLen) {\n revert ViewOverrun();\n }\n // Could do the unchecked math due to the check above\n uint256 index_;\n unchecked {\n index_ = viewLen - len_;\n }\n // Build a view starting from index with the given length\n unchecked {\n // len_ \u003c= memView.len() =\u003e memView.loc() \u003c= loc_ \u003c= memView.end()\n return build({loc_: memView.loc() + viewLen - len_, len_: len_});\n }\n }\n\n // ═══════════════════════════════════════════ INDEXING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Load up to 32 bytes from the view onto the stack.\n * @dev Returns a bytes32 with only the `bytes_` HIGHEST bytes set.\n * This can be immediately cast to a smaller fixed-length byte array.\n * To automatically cast to an integer, use `indexUint`.\n * @param memView The memory view\n * @param index_ The index\n * @param bytes_ The amount of bytes to load onto the stack\n * @return result The 32 byte result having only `bytes_` highest bytes set\n */\n function index(MemView memView, uint256 index_, uint256 bytes_) internal pure returns (bytes32 result) {\n if (bytes_ == 0) {\n return bytes32(0);\n }\n // Can't load more than 32 bytes to the stack in one go\n if (bytes_ \u003e 32) {\n revert IndexedTooMuch();\n }\n // The last indexed byte should be within view boundaries\n if (index_ + bytes_ \u003e memView.len()) {\n revert ViewOverrun();\n }\n uint256 bitLength = bytes_ \u003c\u003c 3; // bytes_ * 8\n uint256 loc_ = memView.loc();\n // Get a mask with `bitLength` highest bits set\n uint256 mask;\n // 0x800...00 binary representation is 100...00\n // sar stands for \"signed arithmetic shift\": https://en.wikipedia.org/wiki/Arithmetic_shift\n // sar(N-1, 100...00) = 11...100..00, with exactly N highest bits set to 1\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n mask := sar(sub(bitLength, 1), 0x8000000000000000000000000000000000000000000000000000000000000000)\n }\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load a full word using index offset, and apply mask to ignore non-relevant bytes\n result := and(mload(add(loc_, index_)), mask)\n }\n }\n\n /**\n * @notice Parse an unsigned integer from the view at `index`.\n * @dev Requires that the view have \u003e= `bytes_` bytes following that index.\n * @param memView The memory view\n * @param index_ The index\n * @param bytes_ The amount of bytes to load onto the stack\n * @return The unsigned integer\n */\n function indexUint(MemView memView, uint256 index_, uint256 bytes_) internal pure returns (uint256) {\n bytes32 indexedBytes = memView.index(index_, bytes_);\n // `index()` returns left-aligned `bytes_`, while integers are right-aligned\n // Shifting here to right-align with the full 32 bytes word: need to shift right `(32 - bytes_)` bytes\n unchecked {\n // memView.index() reverts when bytes_ \u003e 32, thus unchecked math\n return uint256(indexedBytes) \u003e\u003e ((32 - bytes_) \u003c\u003c 3);\n }\n }\n\n /**\n * @notice Parse an address from the view at `index`.\n * @dev Requires that the view have \u003e= 20 bytes following that index.\n * @param memView The memory view\n * @param index_ The index\n * @return The address\n */\n function indexAddress(MemView memView, uint256 index_) internal pure returns (address) {\n // index 20 bytes as `uint160`, and then cast to `address`\n return address(uint160(memView.indexUint(index_, 20)));\n }\n\n // ══════════════════════════════════════════════ PRIVATE HELPERS ══════════════════════════════════════════════════\n\n /// @dev Returns a memory view over the specified memory location\n /// without checking if it points to unallocated memory.\n function _unsafeBuildUnchecked(uint256 loc_, uint256 len_) private pure returns (MemView) {\n // There is no scenario where loc or len would overflow uint128, so we omit this check.\n // We use the highest 128 bits to encode the location and the lowest 128 bits to encode the length.\n return MemView.wrap((loc_ \u003c\u003c 128) | len_);\n }\n\n /**\n * @notice Copy the view to a location, return an unsafe memory reference\n * @dev Super Dangerous direct memory access.\n * This reference can be overwritten if anything else modifies memory (!!!).\n * As such it MUST be consumed IMMEDIATELY. Update the free memory pointer to ensure the copied data\n * is not overwritten. This function is private to prevent unsafe usage by callers.\n * @param memView The memory view\n * @param newLoc The new location to copy the underlying view data\n * @return The memory view over the unsafe memory with the copied underlying data\n */\n function _unsafeCopyTo(MemView memView, uint256 newLoc) private view returns (MemView) {\n uint256 len_ = memView.len();\n uint256 oldLoc = memView.loc();\n\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n }\n // Revert if we're writing in occupied memory\n if (newLoc \u003c ptr) {\n revert OccupiedMemory();\n }\n bool res;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // use the identity precompile (0x04) to copy\n res := staticcall(gas(), 0x04, oldLoc, len_, newLoc, len_)\n }\n if (!res) revert PrecompileOutOfGas();\n return _unsafeBuildUnchecked({loc_: newLoc, len_: len_});\n }\n\n /**\n * @notice Join the views in memory, return an unsafe reference to the memory.\n * @dev Super Dangerous direct memory access.\n * This reference can be overwritten if anything else modifies memory (!!!).\n * As such it MUST be consumed IMMEDIATELY. Update the free memory pointer to ensure the copied data\n * is not overwritten. This function is private to prevent unsafe usage by callers.\n * @param memViews The memory views\n * @return The conjoined view pointing to the new memory\n */\n function _unsafeJoin(MemView[] memory memViews, uint256 location) private view returns (MemView) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n }\n // Revert if we're writing in occupied memory\n if (location \u003c ptr) {\n revert OccupiedMemory();\n }\n // Copy the views to the specified location one by one, by tracking the amount of copied bytes so far\n uint256 offset = 0;\n for (uint256 i = 0; i \u003c memViews.length;) {\n MemView memView = memViews[i];\n // We can use the unchecked math here as location + sum(view.length) will never overflow uint256\n unchecked {\n _unsafeCopyTo(memView, location + offset);\n offset += memView.len();\n ++i;\n }\n }\n return _unsafeBuildUnchecked({loc_: location, len_: offset});\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// contracts/libs/memory/State.sol\n\n/// State is a memory view over a formatted state payload.\ntype State is uint256;\n\nusing StateLib for State global;\n\n/// # State\n/// State structure represents the state of Origin contract at some point of time.\n/// - State is structured in a way to track the updates of the Origin Merkle Tree.\n/// - State includes root of the Origin Merkle Tree, origin domain and some additional metadata.\n/// ## Origin Merkle Tree\n/// Hash of every sent message is inserted in the Origin Merkle Tree, which changes\n/// the value of Origin Merkle Root (which is the root for the mentioned tree).\n/// - Origin has a single Merkle Tree for all messages, regardless of their destination domain.\n/// - This leads to Origin state being updated if and only if a message was sent in a block.\n/// - Origin contract is a \"source of truth\" for states: a state is considered \"valid\" in its Origin,\n/// if it matches the state of the Origin contract after the N-th (nonce) message was sent.\n///\n/// # Memory layout of State fields\n///\n/// | Position | Field | Type | Bytes | Description |\n/// | ---------- | ----------- | ------- | ----- | ------------------------------ |\n/// | [000..032) | root | bytes32 | 32 | Root of the Origin Merkle Tree |\n/// | [032..036) | origin | uint32 | 4 | Domain where Origin is located |\n/// | [036..040) | nonce | uint32 | 4 | Amount of sent messages |\n/// | [040..045) | blockNumber | uint40 | 5 | Block of last sent message |\n/// | [045..050) | timestamp | uint40 | 5 | Time of last sent message |\n/// | [050..062) | gasData | uint96 | 12 | Gas data for the chain |\n///\n/// @dev State could be used to form a Snapshot to be signed by a Guard or a Notary.\nlibrary StateLib {\n using MemViewLib for bytes;\n\n /// @dev The variables below are not supposed to be used outside of the library directly.\n uint256 private constant OFFSET_ROOT = 0;\n uint256 private constant OFFSET_ORIGIN = 32;\n uint256 private constant OFFSET_NONCE = 36;\n uint256 private constant OFFSET_BLOCK_NUMBER = 40;\n uint256 private constant OFFSET_TIMESTAMP = 45;\n uint256 private constant OFFSET_GAS_DATA = 50;\n\n // ═══════════════════════════════════════════════════ STATE ═══════════════════════════════════════════════════════\n\n /**\n * @notice Returns a formatted State payload with provided fields\n * @param root_ New merkle root\n * @param origin_ Domain of Origin's chain\n * @param nonce_ Nonce of the merkle root\n * @param blockNumber_ Block number when root was saved in Origin\n * @param timestamp_ Block timestamp when root was saved in Origin\n * @param gasData_ Gas data for the chain\n * @return Formatted state\n */\n function formatState(\n bytes32 root_,\n uint32 origin_,\n uint32 nonce_,\n uint40 blockNumber_,\n uint40 timestamp_,\n GasData gasData_\n ) internal pure returns (bytes memory) {\n return abi.encodePacked(root_, origin_, nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n /**\n * @notice Returns a State view over the given payload.\n * @dev Will revert if the payload is not a state.\n */\n function castToState(bytes memory payload) internal pure returns (State) {\n return castToState(payload.ref());\n }\n\n /**\n * @notice Casts a memory view to a State view.\n * @dev Will revert if the memory view is not over a state.\n */\n function castToState(MemView memView) internal pure returns (State) {\n if (!isState(memView)) revert UnformattedState();\n return State.wrap(MemView.unwrap(memView));\n }\n\n /// @notice Checks that a payload is a formatted State.\n function isState(MemView memView) internal pure returns (bool) {\n return memView.len() == STATE_LENGTH;\n }\n\n /// @notice Returns the hash of a State, that could be later signed by a Guard to signal\n /// that the state is invalid.\n function hashInvalid(State state) internal pure returns (bytes32) {\n // The final hash to sign is keccak(stateInvalidSalt, keccak(state))\n return state.unwrap().keccakSalted(STATE_INVALID_SALT);\n }\n\n /// @notice Convenience shortcut for unwrapping a view.\n function unwrap(State state) internal pure returns (MemView) {\n return MemView.wrap(State.unwrap(state));\n }\n\n /// @notice Compares two State structures.\n function equals(State a, State b) internal pure returns (bool) {\n // Length of a State payload is fixed, so we just need to compare the hashes\n return a.unwrap().keccak() == b.unwrap().keccak();\n }\n\n // ═══════════════════════════════════════════════ STATE HASHING ═══════════════════════════════════════════════════\n\n /// @notice Returns the hash of the State.\n /// @dev We are using the Merkle Root of a tree with two leafs (see below) as state hash.\n function leaf(State state) internal pure returns (bytes32) {\n (bytes32 leftLeaf_, bytes32 rightLeaf_) = state.subLeafs();\n // Final hash is the parent of these leafs\n return keccak256(bytes.concat(leftLeaf_, rightLeaf_));\n }\n\n /// @notice Returns \"sub-leafs\" of the State. Hash of these \"sub leafs\" is going to be used\n /// as a \"state leaf\" in the \"Snapshot Merkle Tree\".\n /// This enables proving that leftLeaf = (root, origin) was a part of the \"Snapshot Merkle Tree\",\n /// by combining `rightLeaf` with the remainder of the \"Snapshot Merkle Proof\".\n function subLeafs(State state) internal pure returns (bytes32 leftLeaf_, bytes32 rightLeaf_) {\n MemView memView = state.unwrap();\n // Left leaf is (root, origin)\n leftLeaf_ = memView.prefix({len_: OFFSET_NONCE}).keccak();\n // Right leaf is (metadata), or (nonce, blockNumber, timestamp)\n rightLeaf_ = memView.sliceFrom({index_: OFFSET_NONCE}).keccak();\n }\n\n /// @notice Returns the left \"sub-leaf\" of the State.\n function leftLeaf(bytes32 root_, uint32 origin_) internal pure returns (bytes32) {\n // We use encodePacked here to simulate the State memory layout\n return keccak256(abi.encodePacked(root_, origin_));\n }\n\n /// @notice Returns the right \"sub-leaf\" of the State.\n function rightLeaf(uint32 nonce_, uint40 blockNumber_, uint40 timestamp_, GasData gasData_)\n internal\n pure\n returns (bytes32)\n {\n // We use encodePacked here to simulate the State memory layout\n return keccak256(abi.encodePacked(nonce_, blockNumber_, timestamp_, gasData_));\n }\n\n // ═══════════════════════════════════════════════ STATE SLICING ═══════════════════════════════════════════════════\n\n /// @notice Returns a historical Merkle root from the Origin contract.\n function root(State state) internal pure returns (bytes32) {\n return state.unwrap().index({index_: OFFSET_ROOT, bytes_: 32});\n }\n\n /// @notice Returns domain of chain where the Origin contract is deployed.\n function origin(State state) internal pure returns (uint32) {\n // Can be safely casted to uint32, since we index 4 bytes\n return uint32(state.unwrap().indexUint({index_: OFFSET_ORIGIN, bytes_: 4}));\n }\n\n /// @notice Returns nonce of Origin contract at the time, when `root` was the Merkle root.\n function nonce(State state) internal pure returns (uint32) {\n // Can be safely casted to uint32, since we index 4 bytes\n return uint32(state.unwrap().indexUint({index_: OFFSET_NONCE, bytes_: 4}));\n }\n\n /// @notice Returns a block number when `root` was saved in Origin.\n function blockNumber(State state) internal pure returns (uint40) {\n // Can be safely casted to uint40, since we index 5 bytes\n return uint40(state.unwrap().indexUint({index_: OFFSET_BLOCK_NUMBER, bytes_: 5}));\n }\n\n /// @notice Returns a block timestamp when `root` was saved in Origin.\n /// @dev This is the timestamp according to the origin chain.\n function timestamp(State state) internal pure returns (uint40) {\n // Can be safely casted to uint40, since we index 5 bytes\n return uint40(state.unwrap().indexUint({index_: OFFSET_TIMESTAMP, bytes_: 5}));\n }\n\n /// @notice Returns gas data for the chain.\n function gasData(State state) internal pure returns (GasData) {\n return GasDataLib.wrapGasData(state.unwrap().indexUint({index_: OFFSET_GAS_DATA, bytes_: GAS_DATA_LENGTH}));\n }\n}\n\n// test/harnesses/libs/memory/StateHarness.t.sol\n\n// solhint-disable ordering\n/// @notice Exposes State methods for testing against golang.\ncontract StateHarness {\n using StateLib for bytes;\n using StateLib for MemView;\n using MemViewLib for bytes;\n\n // Note: we don't add an empty test() function here, as it currently leads\n // to zero coverage on the corresponding library.\n\n // ══════════════════════════════════════════════════ GETTERS ══════════════════════════════════════════════════════\n\n function castToState(bytes memory payload) public view returns (bytes memory) {\n // Walkaround to get the forge coverage working on libraries, see\n // https://github.com/foundry-rs/foundry/pull/3128#issuecomment-1241245086\n State state = StateLib.castToState(payload);\n return state.unwrap().clone();\n }\n\n function equals(bytes memory a, bytes memory b) public pure returns (bool) {\n return a.castToState().equals(b.castToState());\n }\n\n function hashInvalid(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().hashInvalid();\n }\n\n function leaf(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().leaf();\n }\n\n function subLeafs(bytes memory payload) public pure returns (bytes32, bytes32) {\n return payload.castToState().subLeafs();\n }\n\n function leftLeaf(bytes32 root_, uint32 origin_) public pure returns (bytes32) {\n return StateLib.leftLeaf(root_, origin_);\n }\n\n function rightLeaf(uint32 nonce_, uint40 blockNumber_, uint40 timestamp_, GasData gasData_)\n public\n pure\n returns (bytes32)\n {\n return StateLib.rightLeaf(nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n function root(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().root();\n }\n\n function origin(bytes memory payload) public pure returns (uint32) {\n return payload.castToState().origin();\n }\n\n function nonce(bytes memory payload) public pure returns (uint32) {\n return payload.castToState().nonce();\n }\n\n function blockNumber(bytes memory payload) public pure returns (uint40) {\n return payload.castToState().blockNumber();\n }\n\n function timestamp(bytes memory payload) public pure returns (uint40) {\n return payload.castToState().timestamp();\n }\n\n function gasData(bytes memory payload) public pure returns (GasData) {\n return payload.castToState().gasData();\n }\n\n // ════════════════════════════════════════════════ FORMATTERS ═════════════════════════════════════════════════════\n\n function formatState(\n bytes32 root_,\n uint32 origin_,\n uint32 nonce_,\n uint40 blockNumber_,\n uint40 timestamp_,\n GasData gasData_\n ) public pure returns (bytes memory) {\n return StateLib.formatState(root_, origin_, nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n function isState(bytes memory payload) public pure returns (bool) {\n return payload.ref().isState();\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":"15779:19162:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;15779:19162:0;;;;;;;;;;;;;;;;;","srcMapRuntime":"15779:19162:0:-:0;;;;;;;;","abiDefinition":[],"userDoc":{"kind":"user","methods":{},"notice":"Library for operations with the memory views. Forked from https://github.com/summa-tx/memview-sol with several breaking changes: - The codebase is ported to Solidity 0.8 - Custom errors are added - The runtime type checking is replaced with compile-time check provided by User-Defined Value Types https://docs.soliditylang.org/en/latest/types.html#user-defined-value-types - uint256 is used as the underlying type for the \"memory view\" instead of bytes29. It is wrapped into MemView custom type in order not to be confused with actual integers. - Therefore the \"type\" field is discarded, allowing to allocate 16 bytes for both view location and length - The documentation is expanded - Library functions unused by the rest of the codebase are removed","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 operations with the memory views. Forked from https://github.com/summa-tx/memview-sol with several breaking changes: - The codebase is ported to Solidity 0.8 - Custom errors are added - The runtime type checking is replaced with compile-time check provided by User-Defined Value Types https://docs.soliditylang.org/en/latest/types.html#user-defined-value-types - uint256 is used as the underlying type for the \\\"memory view\\\" instead of bytes29. It is wrapped into MemView custom type in order not to be confused with actual integers. - Therefore the \\\"type\\\" field is discarded, allowing to allocate 16 bytes for both view location and length - The documentation is expanded - Library functions unused by the rest of the codebase are removed\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/StateHarness.t.sol\":\"MemViewLib\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/StateHarness.t.sol\":{\"keccak256\":\"0x18cffce3039e8ab774b0011a4bbf9812533e064bdfebfe70b931ec2427614089\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://d1081451a985d6522077ce9dd2bf81a2d3f726e1003a3b588240ed416968ee36\",\"dweb:/ipfs/QmPmWLB1F2KzmCwmr1KTwFbPtHnE11Axr386vjrBc4aWM9\"]}},\"version\":1}"},"hashes":{}},"solidity/StateHarness.t.sol:NumberLib":{"code":"0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220e2667737d60b8029b7b0285bde8d4ed2acb8aa7a03430483a397e5ef36fb3a7164736f6c63430008110033","runtime-code":"0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220e2667737d60b8029b7b0285bde8d4ed2acb8aa7a03430483a397e5ef36fb3a7164736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17;\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// contracts/libs/memory/MemView.sol\n\n/// @dev MemView is an untyped view over a portion of memory to be used instead of `bytes memory`\ntype MemView is uint256;\n\n/// @dev Attach library functions to MemView\nusing MemViewLib for MemView global;\n\n/// @notice Library for operations with the memory views.\n/// Forked from https://github.com/summa-tx/memview-sol with several breaking changes:\n/// - The codebase is ported to Solidity 0.8\n/// - Custom errors are added\n/// - The runtime type checking is replaced with compile-time check provided by User-Defined Value Types\n/// https://docs.soliditylang.org/en/latest/types.html#user-defined-value-types\n/// - uint256 is used as the underlying type for the \"memory view\" instead of bytes29.\n/// It is wrapped into MemView custom type in order not to be confused with actual integers.\n/// - Therefore the \"type\" field is discarded, allowing to allocate 16 bytes for both view location and length\n/// - The documentation is expanded\n/// - Library functions unused by the rest of the codebase are removed\n// - Very pretty code separators are added :)\nlibrary MemViewLib {\n /// @notice Stack layout for uint256 (from highest bits to lowest)\n /// (32 .. 16] loc 16 bytes Memory address of underlying bytes\n /// (16 .. 00] len 16 bytes Length of underlying bytes\n\n // ═══════════════════════════════════════════ BUILDING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Instantiate a new untyped memory view. This should generally not be called directly.\n * Prefer `ref` wherever possible.\n * @param loc_ The memory address\n * @param len_ The length\n * @return The new view with the specified location and length\n */\n function build(uint256 loc_, uint256 len_) internal pure returns (MemView) {\n uint256 end_ = loc_ + len_;\n // Make sure that a view is not constructed that points to unallocated memory\n // as this could be indicative of a buffer overflow attack\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n if gt(end_, mload(0x40)) { end_ := 0 }\n }\n if (end_ == 0) {\n revert UnallocatedMemory();\n }\n return _unsafeBuildUnchecked(loc_, len_);\n }\n\n /**\n * @notice Instantiate a memory view from a byte array.\n * @dev Note that due to Solidity memory representation, it is not possible to\n * implement a deref, as the `bytes` type stores its len in memory.\n * @param arr The byte array\n * @return The memory view over the provided byte array\n */\n function ref(bytes memory arr) internal pure returns (MemView) {\n uint256 len_ = arr.length;\n // `bytes arr` is stored in memory in the following way\n // 1. First, uint256 arr.length is stored. That requires 32 bytes (0x20).\n // 2. Then, the array data is stored.\n uint256 loc_;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // We add 0x20, so that the view starts exactly where the array data starts\n loc_ := add(arr, 0x20)\n }\n return build(loc_, len_);\n }\n\n // ════════════════════════════════════════════ CLONING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Copies the referenced memory to a new loc in memory, returning a `bytes` pointing to the new memory.\n * @param memView The memory view\n * @return arr The cloned byte array\n */\n function clone(MemView memView) internal view returns (bytes memory arr) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n // This is where the byte array will be stored\n arr := ptr\n }\n unchecked {\n _unsafeCopyTo(memView, ptr + 0x20);\n }\n // `bytes arr` is stored in memory in the following way\n // 1. First, uint256 arr.length is stored. That requires 32 bytes (0x20).\n // 2. Then, the array data is stored.\n uint256 len_ = memView.len();\n uint256 footprint_ = memView.footprint();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Write new unused pointer: the old value + array footprint + 32 bytes to store the length\n mstore(0x40, add(add(ptr, footprint_), 0x20))\n // Write len of new array (in bytes)\n mstore(ptr, len_)\n }\n }\n\n /**\n * @notice Copies all views, joins them into a new bytearray.\n * @param memViews The memory views\n * @return arr The new byte array with joined data behind the given views\n */\n function join(MemView[] memory memViews) internal view returns (bytes memory arr) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n // This is where the byte array will be stored\n arr := ptr\n }\n MemView newView;\n unchecked {\n newView = _unsafeJoin(memViews, ptr + 0x20);\n }\n uint256 len_ = newView.len();\n uint256 footprint_ = newView.footprint();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Write new unused pointer: the old value + array footprint + 32 bytes to store the length\n mstore(0x40, add(add(ptr, footprint_), 0x20))\n // Write len of new array (in bytes)\n mstore(ptr, len_)\n }\n }\n\n // ══════════════════════════════════════════ INSPECTING MEMORY VIEW ═══════════════════════════════════════════════\n\n /**\n * @notice Returns the memory address of the underlying bytes.\n * @param memView The memory view\n * @return loc_ The memory address\n */\n function loc(MemView memView) internal pure returns (uint256 loc_) {\n // loc is stored in the highest 16 bytes of the underlying uint256\n return MemView.unwrap(memView) \u003e\u003e 128;\n }\n\n /**\n * @notice Returns the number of bytes of the view.\n * @param memView The memory view\n * @return len_ The length of the view\n */\n function len(MemView memView) internal pure returns (uint256 len_) {\n // len is stored in the lowest 16 bytes of the underlying uint256\n return MemView.unwrap(memView) \u0026 type(uint128).max;\n }\n\n /**\n * @notice Returns the endpoint of `memView`.\n * @param memView The memory view\n * @return end_ The endpoint of `memView`\n */\n function end(MemView memView) internal pure returns (uint256 end_) {\n // The endpoint never overflows uint128, let alone uint256, so we could use unchecked math here\n unchecked {\n return memView.loc() + memView.len();\n }\n }\n\n /**\n * @notice Returns the number of memory words this memory view occupies, rounded up.\n * @param memView The memory view\n * @return words_ The number of memory words\n */\n function words(MemView memView) internal pure returns (uint256 words_) {\n // returning ceil(length / 32.0)\n unchecked {\n return (memView.len() + 31) \u003e\u003e 5;\n }\n }\n\n /**\n * @notice Returns the in-memory footprint of a fresh copy of the view.\n * @param memView The memory view\n * @return footprint_ The in-memory footprint of a fresh copy of the view.\n */\n function footprint(MemView memView) internal pure returns (uint256 footprint_) {\n // words() * 32\n return memView.words() \u003c\u003c 5;\n }\n\n // ════════════════════════════════════════════ HASHING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Returns the keccak256 hash of the underlying memory\n * @param memView The memory view\n * @return digest The keccak256 hash of the underlying memory\n */\n function keccak(MemView memView) internal pure returns (bytes32 digest) {\n uint256 loc_ = memView.loc();\n uint256 len_ = memView.len();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n digest := keccak256(loc_, len_)\n }\n }\n\n /**\n * @notice Adds a salt to the keccak256 hash of the underlying data and returns the keccak256 hash of the\n * resulting data.\n * @param memView The memory view\n * @return digestSalted keccak256(salt, keccak256(memView))\n */\n function keccakSalted(MemView memView, bytes32 salt) internal pure returns (bytes32 digestSalted) {\n return keccak256(bytes.concat(salt, memView.keccak()));\n }\n\n // ════════════════════════════════════════════ SLICING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Safe slicing without memory modification.\n * @param memView The memory view\n * @param index_ The start index\n * @param len_ The length\n * @return The new view for the slice of the given length starting from the given index\n */\n function slice(MemView memView, uint256 index_, uint256 len_) internal pure returns (MemView) {\n uint256 loc_ = memView.loc();\n // Ensure it doesn't overrun the view\n if (loc_ + index_ + len_ \u003e memView.end()) {\n revert ViewOverrun();\n }\n // Build a view starting from index with the given length\n unchecked {\n // loc_ + index_ \u003c= memView.end()\n return build({loc_: loc_ + index_, len_: len_});\n }\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing bytes from `index` to end(memView).\n * @param memView The memory view\n * @param index_ The start index\n * @return The new view for the slice starting from the given index until the initial view endpoint\n */\n function sliceFrom(MemView memView, uint256 index_) internal pure returns (MemView) {\n uint256 len_ = memView.len();\n // Ensure it doesn't overrun the view\n if (index_ \u003e len_) {\n revert ViewOverrun();\n }\n // Build a view starting from index with the given length\n unchecked {\n // index_ \u003c= len_ =\u003e memView.loc() + index_ \u003c= memView.loc() + memView.len() == memView.end()\n return build({loc_: memView.loc() + index_, len_: len_ - index_});\n }\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing the first `len` bytes.\n * @param memView The memory view\n * @param len_ The length\n * @return The new view for the slice of the given length starting from the initial view beginning\n */\n function prefix(MemView memView, uint256 len_) internal pure returns (MemView) {\n return memView.slice({index_: 0, len_: len_});\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing the last `len` byte.\n * @param memView The memory view\n * @param len_ The length\n * @return The new view for the slice of the given length until the initial view endpoint\n */\n function postfix(MemView memView, uint256 len_) internal pure returns (MemView) {\n uint256 viewLen = memView.len();\n // Ensure it doesn't overrun the view\n if (len_ \u003e viewLen) {\n revert ViewOverrun();\n }\n // Could do the unchecked math due to the check above\n uint256 index_;\n unchecked {\n index_ = viewLen - len_;\n }\n // Build a view starting from index with the given length\n unchecked {\n // len_ \u003c= memView.len() =\u003e memView.loc() \u003c= loc_ \u003c= memView.end()\n return build({loc_: memView.loc() + viewLen - len_, len_: len_});\n }\n }\n\n // ═══════════════════════════════════════════ INDEXING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Load up to 32 bytes from the view onto the stack.\n * @dev Returns a bytes32 with only the `bytes_` HIGHEST bytes set.\n * This can be immediately cast to a smaller fixed-length byte array.\n * To automatically cast to an integer, use `indexUint`.\n * @param memView The memory view\n * @param index_ The index\n * @param bytes_ The amount of bytes to load onto the stack\n * @return result The 32 byte result having only `bytes_` highest bytes set\n */\n function index(MemView memView, uint256 index_, uint256 bytes_) internal pure returns (bytes32 result) {\n if (bytes_ == 0) {\n return bytes32(0);\n }\n // Can't load more than 32 bytes to the stack in one go\n if (bytes_ \u003e 32) {\n revert IndexedTooMuch();\n }\n // The last indexed byte should be within view boundaries\n if (index_ + bytes_ \u003e memView.len()) {\n revert ViewOverrun();\n }\n uint256 bitLength = bytes_ \u003c\u003c 3; // bytes_ * 8\n uint256 loc_ = memView.loc();\n // Get a mask with `bitLength` highest bits set\n uint256 mask;\n // 0x800...00 binary representation is 100...00\n // sar stands for \"signed arithmetic shift\": https://en.wikipedia.org/wiki/Arithmetic_shift\n // sar(N-1, 100...00) = 11...100..00, with exactly N highest bits set to 1\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n mask := sar(sub(bitLength, 1), 0x8000000000000000000000000000000000000000000000000000000000000000)\n }\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load a full word using index offset, and apply mask to ignore non-relevant bytes\n result := and(mload(add(loc_, index_)), mask)\n }\n }\n\n /**\n * @notice Parse an unsigned integer from the view at `index`.\n * @dev Requires that the view have \u003e= `bytes_` bytes following that index.\n * @param memView The memory view\n * @param index_ The index\n * @param bytes_ The amount of bytes to load onto the stack\n * @return The unsigned integer\n */\n function indexUint(MemView memView, uint256 index_, uint256 bytes_) internal pure returns (uint256) {\n bytes32 indexedBytes = memView.index(index_, bytes_);\n // `index()` returns left-aligned `bytes_`, while integers are right-aligned\n // Shifting here to right-align with the full 32 bytes word: need to shift right `(32 - bytes_)` bytes\n unchecked {\n // memView.index() reverts when bytes_ \u003e 32, thus unchecked math\n return uint256(indexedBytes) \u003e\u003e ((32 - bytes_) \u003c\u003c 3);\n }\n }\n\n /**\n * @notice Parse an address from the view at `index`.\n * @dev Requires that the view have \u003e= 20 bytes following that index.\n * @param memView The memory view\n * @param index_ The index\n * @return The address\n */\n function indexAddress(MemView memView, uint256 index_) internal pure returns (address) {\n // index 20 bytes as `uint160`, and then cast to `address`\n return address(uint160(memView.indexUint(index_, 20)));\n }\n\n // ══════════════════════════════════════════════ PRIVATE HELPERS ══════════════════════════════════════════════════\n\n /// @dev Returns a memory view over the specified memory location\n /// without checking if it points to unallocated memory.\n function _unsafeBuildUnchecked(uint256 loc_, uint256 len_) private pure returns (MemView) {\n // There is no scenario where loc or len would overflow uint128, so we omit this check.\n // We use the highest 128 bits to encode the location and the lowest 128 bits to encode the length.\n return MemView.wrap((loc_ \u003c\u003c 128) | len_);\n }\n\n /**\n * @notice Copy the view to a location, return an unsafe memory reference\n * @dev Super Dangerous direct memory access.\n * This reference can be overwritten if anything else modifies memory (!!!).\n * As such it MUST be consumed IMMEDIATELY. Update the free memory pointer to ensure the copied data\n * is not overwritten. This function is private to prevent unsafe usage by callers.\n * @param memView The memory view\n * @param newLoc The new location to copy the underlying view data\n * @return The memory view over the unsafe memory with the copied underlying data\n */\n function _unsafeCopyTo(MemView memView, uint256 newLoc) private view returns (MemView) {\n uint256 len_ = memView.len();\n uint256 oldLoc = memView.loc();\n\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n }\n // Revert if we're writing in occupied memory\n if (newLoc \u003c ptr) {\n revert OccupiedMemory();\n }\n bool res;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // use the identity precompile (0x04) to copy\n res := staticcall(gas(), 0x04, oldLoc, len_, newLoc, len_)\n }\n if (!res) revert PrecompileOutOfGas();\n return _unsafeBuildUnchecked({loc_: newLoc, len_: len_});\n }\n\n /**\n * @notice Join the views in memory, return an unsafe reference to the memory.\n * @dev Super Dangerous direct memory access.\n * This reference can be overwritten if anything else modifies memory (!!!).\n * As such it MUST be consumed IMMEDIATELY. Update the free memory pointer to ensure the copied data\n * is not overwritten. This function is private to prevent unsafe usage by callers.\n * @param memViews The memory views\n * @return The conjoined view pointing to the new memory\n */\n function _unsafeJoin(MemView[] memory memViews, uint256 location) private view returns (MemView) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n }\n // Revert if we're writing in occupied memory\n if (location \u003c ptr) {\n revert OccupiedMemory();\n }\n // Copy the views to the specified location one by one, by tracking the amount of copied bytes so far\n uint256 offset = 0;\n for (uint256 i = 0; i \u003c memViews.length;) {\n MemView memView = memViews[i];\n // We can use the unchecked math here as location + sum(view.length) will never overflow uint256\n unchecked {\n _unsafeCopyTo(memView, location + offset);\n offset += memView.len();\n ++i;\n }\n }\n return _unsafeBuildUnchecked({loc_: location, len_: offset});\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// contracts/libs/memory/State.sol\n\n/// State is a memory view over a formatted state payload.\ntype State is uint256;\n\nusing StateLib for State global;\n\n/// # State\n/// State structure represents the state of Origin contract at some point of time.\n/// - State is structured in a way to track the updates of the Origin Merkle Tree.\n/// - State includes root of the Origin Merkle Tree, origin domain and some additional metadata.\n/// ## Origin Merkle Tree\n/// Hash of every sent message is inserted in the Origin Merkle Tree, which changes\n/// the value of Origin Merkle Root (which is the root for the mentioned tree).\n/// - Origin has a single Merkle Tree for all messages, regardless of their destination domain.\n/// - This leads to Origin state being updated if and only if a message was sent in a block.\n/// - Origin contract is a \"source of truth\" for states: a state is considered \"valid\" in its Origin,\n/// if it matches the state of the Origin contract after the N-th (nonce) message was sent.\n///\n/// # Memory layout of State fields\n///\n/// | Position | Field | Type | Bytes | Description |\n/// | ---------- | ----------- | ------- | ----- | ------------------------------ |\n/// | [000..032) | root | bytes32 | 32 | Root of the Origin Merkle Tree |\n/// | [032..036) | origin | uint32 | 4 | Domain where Origin is located |\n/// | [036..040) | nonce | uint32 | 4 | Amount of sent messages |\n/// | [040..045) | blockNumber | uint40 | 5 | Block of last sent message |\n/// | [045..050) | timestamp | uint40 | 5 | Time of last sent message |\n/// | [050..062) | gasData | uint96 | 12 | Gas data for the chain |\n///\n/// @dev State could be used to form a Snapshot to be signed by a Guard or a Notary.\nlibrary StateLib {\n using MemViewLib for bytes;\n\n /// @dev The variables below are not supposed to be used outside of the library directly.\n uint256 private constant OFFSET_ROOT = 0;\n uint256 private constant OFFSET_ORIGIN = 32;\n uint256 private constant OFFSET_NONCE = 36;\n uint256 private constant OFFSET_BLOCK_NUMBER = 40;\n uint256 private constant OFFSET_TIMESTAMP = 45;\n uint256 private constant OFFSET_GAS_DATA = 50;\n\n // ═══════════════════════════════════════════════════ STATE ═══════════════════════════════════════════════════════\n\n /**\n * @notice Returns a formatted State payload with provided fields\n * @param root_ New merkle root\n * @param origin_ Domain of Origin's chain\n * @param nonce_ Nonce of the merkle root\n * @param blockNumber_ Block number when root was saved in Origin\n * @param timestamp_ Block timestamp when root was saved in Origin\n * @param gasData_ Gas data for the chain\n * @return Formatted state\n */\n function formatState(\n bytes32 root_,\n uint32 origin_,\n uint32 nonce_,\n uint40 blockNumber_,\n uint40 timestamp_,\n GasData gasData_\n ) internal pure returns (bytes memory) {\n return abi.encodePacked(root_, origin_, nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n /**\n * @notice Returns a State view over the given payload.\n * @dev Will revert if the payload is not a state.\n */\n function castToState(bytes memory payload) internal pure returns (State) {\n return castToState(payload.ref());\n }\n\n /**\n * @notice Casts a memory view to a State view.\n * @dev Will revert if the memory view is not over a state.\n */\n function castToState(MemView memView) internal pure returns (State) {\n if (!isState(memView)) revert UnformattedState();\n return State.wrap(MemView.unwrap(memView));\n }\n\n /// @notice Checks that a payload is a formatted State.\n function isState(MemView memView) internal pure returns (bool) {\n return memView.len() == STATE_LENGTH;\n }\n\n /// @notice Returns the hash of a State, that could be later signed by a Guard to signal\n /// that the state is invalid.\n function hashInvalid(State state) internal pure returns (bytes32) {\n // The final hash to sign is keccak(stateInvalidSalt, keccak(state))\n return state.unwrap().keccakSalted(STATE_INVALID_SALT);\n }\n\n /// @notice Convenience shortcut for unwrapping a view.\n function unwrap(State state) internal pure returns (MemView) {\n return MemView.wrap(State.unwrap(state));\n }\n\n /// @notice Compares two State structures.\n function equals(State a, State b) internal pure returns (bool) {\n // Length of a State payload is fixed, so we just need to compare the hashes\n return a.unwrap().keccak() == b.unwrap().keccak();\n }\n\n // ═══════════════════════════════════════════════ STATE HASHING ═══════════════════════════════════════════════════\n\n /// @notice Returns the hash of the State.\n /// @dev We are using the Merkle Root of a tree with two leafs (see below) as state hash.\n function leaf(State state) internal pure returns (bytes32) {\n (bytes32 leftLeaf_, bytes32 rightLeaf_) = state.subLeafs();\n // Final hash is the parent of these leafs\n return keccak256(bytes.concat(leftLeaf_, rightLeaf_));\n }\n\n /// @notice Returns \"sub-leafs\" of the State. Hash of these \"sub leafs\" is going to be used\n /// as a \"state leaf\" in the \"Snapshot Merkle Tree\".\n /// This enables proving that leftLeaf = (root, origin) was a part of the \"Snapshot Merkle Tree\",\n /// by combining `rightLeaf` with the remainder of the \"Snapshot Merkle Proof\".\n function subLeafs(State state) internal pure returns (bytes32 leftLeaf_, bytes32 rightLeaf_) {\n MemView memView = state.unwrap();\n // Left leaf is (root, origin)\n leftLeaf_ = memView.prefix({len_: OFFSET_NONCE}).keccak();\n // Right leaf is (metadata), or (nonce, blockNumber, timestamp)\n rightLeaf_ = memView.sliceFrom({index_: OFFSET_NONCE}).keccak();\n }\n\n /// @notice Returns the left \"sub-leaf\" of the State.\n function leftLeaf(bytes32 root_, uint32 origin_) internal pure returns (bytes32) {\n // We use encodePacked here to simulate the State memory layout\n return keccak256(abi.encodePacked(root_, origin_));\n }\n\n /// @notice Returns the right \"sub-leaf\" of the State.\n function rightLeaf(uint32 nonce_, uint40 blockNumber_, uint40 timestamp_, GasData gasData_)\n internal\n pure\n returns (bytes32)\n {\n // We use encodePacked here to simulate the State memory layout\n return keccak256(abi.encodePacked(nonce_, blockNumber_, timestamp_, gasData_));\n }\n\n // ═══════════════════════════════════════════════ STATE SLICING ═══════════════════════════════════════════════════\n\n /// @notice Returns a historical Merkle root from the Origin contract.\n function root(State state) internal pure returns (bytes32) {\n return state.unwrap().index({index_: OFFSET_ROOT, bytes_: 32});\n }\n\n /// @notice Returns domain of chain where the Origin contract is deployed.\n function origin(State state) internal pure returns (uint32) {\n // Can be safely casted to uint32, since we index 4 bytes\n return uint32(state.unwrap().indexUint({index_: OFFSET_ORIGIN, bytes_: 4}));\n }\n\n /// @notice Returns nonce of Origin contract at the time, when `root` was the Merkle root.\n function nonce(State state) internal pure returns (uint32) {\n // Can be safely casted to uint32, since we index 4 bytes\n return uint32(state.unwrap().indexUint({index_: OFFSET_NONCE, bytes_: 4}));\n }\n\n /// @notice Returns a block number when `root` was saved in Origin.\n function blockNumber(State state) internal pure returns (uint40) {\n // Can be safely casted to uint40, since we index 5 bytes\n return uint40(state.unwrap().indexUint({index_: OFFSET_BLOCK_NUMBER, bytes_: 5}));\n }\n\n /// @notice Returns a block timestamp when `root` was saved in Origin.\n /// @dev This is the timestamp according to the origin chain.\n function timestamp(State state) internal pure returns (uint40) {\n // Can be safely casted to uint40, since we index 5 bytes\n return uint40(state.unwrap().indexUint({index_: OFFSET_TIMESTAMP, bytes_: 5}));\n }\n\n /// @notice Returns gas data for the chain.\n function gasData(State state) internal pure returns (GasData) {\n return GasDataLib.wrapGasData(state.unwrap().indexUint({index_: OFFSET_GAS_DATA, bytes_: GAS_DATA_LENGTH}));\n }\n}\n\n// test/harnesses/libs/memory/StateHarness.t.sol\n\n// solhint-disable ordering\n/// @notice Exposes State methods for testing against golang.\ncontract StateHarness {\n using StateLib for bytes;\n using StateLib for MemView;\n using MemViewLib for bytes;\n\n // Note: we don't add an empty test() function here, as it currently leads\n // to zero coverage on the corresponding library.\n\n // ══════════════════════════════════════════════════ GETTERS ══════════════════════════════════════════════════════\n\n function castToState(bytes memory payload) public view returns (bytes memory) {\n // Walkaround to get the forge coverage working on libraries, see\n // https://github.com/foundry-rs/foundry/pull/3128#issuecomment-1241245086\n State state = StateLib.castToState(payload);\n return state.unwrap().clone();\n }\n\n function equals(bytes memory a, bytes memory b) public pure returns (bool) {\n return a.castToState().equals(b.castToState());\n }\n\n function hashInvalid(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().hashInvalid();\n }\n\n function leaf(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().leaf();\n }\n\n function subLeafs(bytes memory payload) public pure returns (bytes32, bytes32) {\n return payload.castToState().subLeafs();\n }\n\n function leftLeaf(bytes32 root_, uint32 origin_) public pure returns (bytes32) {\n return StateLib.leftLeaf(root_, origin_);\n }\n\n function rightLeaf(uint32 nonce_, uint40 blockNumber_, uint40 timestamp_, GasData gasData_)\n public\n pure\n returns (bytes32)\n {\n return StateLib.rightLeaf(nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n function root(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().root();\n }\n\n function origin(bytes memory payload) public pure returns (uint32) {\n return payload.castToState().origin();\n }\n\n function nonce(bytes memory payload) public pure returns (uint32) {\n return payload.castToState().nonce();\n }\n\n function blockNumber(bytes memory payload) public pure returns (uint40) {\n return payload.castToState().blockNumber();\n }\n\n function timestamp(bytes memory payload) public pure returns (uint40) {\n return payload.castToState().timestamp();\n }\n\n function gasData(bytes memory payload) public pure returns (GasData) {\n return payload.castToState().gasData();\n }\n\n // ════════════════════════════════════════════════ FORMATTERS ═════════════════════════════════════════════════════\n\n function formatState(\n bytes32 root_,\n uint32 origin_,\n uint32 nonce_,\n uint40 blockNumber_,\n uint40 timestamp_,\n GasData gasData_\n ) public pure returns (bytes memory) {\n return StateLib.formatState(root_, origin_, nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n function isState(bytes memory payload) public pure returns (bool) {\n return payload.ref().isState();\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":"9791:4887:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;9791:4887:0;;;;;;;;;;;;;;;;;","srcMapRuntime":"9791: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/StateHarness.t.sol\":\"NumberLib\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/StateHarness.t.sol\":{\"keccak256\":\"0x18cffce3039e8ab774b0011a4bbf9812533e064bdfebfe70b931ec2427614089\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://d1081451a985d6522077ce9dd2bf81a2d3f726e1003a3b588240ed416968ee36\",\"dweb:/ipfs/QmPmWLB1F2KzmCwmr1KTwFbPtHnE11Axr386vjrBc4aWM9\"]}},\"version\":1}"},"hashes":{}},"solidity/StateHarness.t.sol:StateHarness":{"code":"0x608060405234801561001057600080fd5b50610ebc806100206000396000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c80639aaa182611610097578063d7a7a72c11610066578063d7a7a72c14610258578063e948e6001461026b578063edaa471d1461027e578063f8cb79431461029157600080fd5b80639aaa1826146101f7578063aae6d8841461021f578063c2e9e20814610232578063cb3eb0e11461024557600080fd5b80634e765004116100d35780634e7650041461016b5780635a0ca172146101935780635fed0261146101c357806360cf3bf0146101d657600080fd5b8063137e618a146100fa57806317ebb0b7146101225780631c9aa22214610142575b600080fd5b61010d610108366004610c10565b6102a4565b60405190151581526020015b60405180910390f35b610135610130366004610cbe565b6102ca565b6040516101199190610d2b565b610155610150366004610d97565b61038d565b60405164ffffffffff9091168152602001610119565b61017e610179366004610d97565b6103a0565b60405163ffffffff9091168152602001610119565b6101a66101a1366004610d97565b6103b3565b6040516bffffffffffffffffffffffff9091168152602001610119565b6101356101d1366004610d97565b6103c6565b6101e96101e4366004610d97565b6103e5565b604051908152602001610119565b61020a610205366004610d97565b6103f8565b60408051928352602083019190915201610119565b61010d61022d366004610d97565b610415565b6101e9610240366004610d97565b610428565b61017e610253366004610d97565b61043b565b6101e9610266366004610d97565b61044e565b610155610279366004610d97565b610461565b6101e961028c366004610dcc565b610474565b6101e961029f366004610df8565b610480565b60006102c16102b28361053a565b6102bb8561053a565b9061054d565b90505b92915050565b60408051602081018890527fffffffff0000000000000000000000000000000000000000000000000000000060e088811b82168385015287901b1660448201527fffffffffff00000000000000000000000000000000000000000000000000000060d886811b8216604884015285901b16604d8201527fffffffffffffffffffffffff000000000000000000000000000000000000000060a084901b1660528201528151808203603e018152605e9091019091526060905b979650505050505050565b60006102c461039b8361053a565b61056e565b60006102c46103ae8361053a565b610580565b60006102c46103c18361053a565b61058f565b606060006103d38361053a565b90506103de816105a4565b9392505050565b60006102c46103f38361053a565b610601565b60008061040c6104078461053a565b61062d565b91509150915091565b60006102c461042383610657565b610672565b60006102c46104368361053a565b61069a565b60006102c46104498361053a565b6106a8565b60006102c461045c8361053a565b6106b7565b60006102c461046f8361053a565b6106f6565b60006102c18383610705565b604080517fffffffff0000000000000000000000000000000000000000000000000000000060e087901b166020808301919091527fffffffffff00000000000000000000000000000000000000000000000000000060d887811b8216602485015286901b1660298301527fffffffffffffffffffffffff000000000000000000000000000000000000000060a085901b16602e8301528251808303601a018152603a90920190925280519101206000905b95945050505050565b60006102c461054883610657565b610766565b600061055d826107ab565b6107ab565b610566846107ab565b149392505050565b60006102c4602d6005845b91906107d6565b60006102c46024600484610579565b60006102c46105a16032600c85610579565b90565b604051806105b583602083016107f7565b506fffffffffffffffffffffffffffffffff83166000601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168301602001604052509052919050565b60006102c4827f43713cd927f8eb63b519f3b180bd5f3708ebbe93666be9ba4b9624b7bc57e6636108a0565b6000808261063f6105588260246108c3565b925061064f6105588260246108d0565b915050915091565b80516000906020830161066a8183610932565b949350505050565b6000610680600c6032610e4c565b6fffffffffffffffffffffffffffffffff83161492915050565b60006102c482826020610995565b60006102c46020600484610579565b60008060006106c58461062d565b6040805160208082019490945280820192909252805180830382018152606090920190528051910120949350505050565b60006102c46028600584610579565b6000828260405160200161074892919091825260e01b7fffffffff0000000000000000000000000000000000000000000000000000000016602082015260240190565b60405160208183030381529060405280519060200120905092915050565b600061077182610672565b6107a7576040517f6ba041c400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5090565b6000806107b88360801c90565b6fffffffffffffffffffffffffffffffff9390931690922092915050565b6000806107e4858585610995565b602084900360031b1c9150509392505050565b6040516000906fffffffffffffffffffffffffffffffff841690608085901c9080851015610851576040517f4b2a158c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008386858560045afa905080610894576040517f7c7d772f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b608086901b8417610382565b6000816108ac846107ab565b604080516020810193909352820152606001610748565b60006102c1838284610a9f565b60006fffffffffffffffffffffffffffffffff83168083111561091f576040517fa3b99ded00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61066a8361092d8660801c90565b018483035b60008061093f8385610e4c565b905060405181111561094f575060005b80600003610989576040517f10bef38600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b608084901b831761066a565b6000816000036109a7575060006103de565b60208211156109e2576040517f31d784a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6fffffffffffffffffffffffffffffffff84166109ff8385610e4c565b1115610a37576040517fa3b99ded00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600382901b6000610a488660801c90565b909401517f80000000000000000000000000000000000000000000000000000000000000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff929092019190911d16949350505050565b600080610aac8560801c90565b9050610ab785610b10565b83610ac28684610e4c565b610acc9190610e4c565b1115610b04576040517fa3b99ded00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61053184820184610932565b60006fffffffffffffffffffffffffffffffff8216610b2f8360801c90565b0192915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f830112610b7657600080fd5b813567ffffffffffffffff80821115610b9157610b91610b36565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715610bd757610bd7610b36565b81604052838152866020858801011115610bf057600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060408385031215610c2357600080fd5b823567ffffffffffffffff80821115610c3b57600080fd5b610c4786838701610b65565b93506020850135915080821115610c5d57600080fd5b50610c6a85828601610b65565b9150509250929050565b803563ffffffff81168114610c8857600080fd5b919050565b803564ffffffffff81168114610c8857600080fd5b80356bffffffffffffffffffffffff81168114610c8857600080fd5b60008060008060008060c08789031215610cd757600080fd5b86359550610ce760208801610c74565b9450610cf560408801610c74565b9350610d0360608801610c8d565b9250610d1160808801610c8d565b9150610d1f60a08801610ca2565b90509295509295509295565b600060208083528351808285015260005b81811015610d5857858101830151858201604001528201610d3c565b5060006040828601015260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8301168501019250505092915050565b600060208284031215610da957600080fd5b813567ffffffffffffffff811115610dc057600080fd5b61066a84828501610b65565b60008060408385031215610ddf57600080fd5b82359150610def60208401610c74565b90509250929050565b60008060008060808587031215610e0e57600080fd5b610e1785610c74565b9350610e2560208601610c8d565b9250610e3360408601610c8d565b9150610e4160608601610ca2565b905092959194509250565b808201808211156102c4577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fdfea2646970667358221220d6e0381525b771a3cf213697c3ed8c03476e756a5ba6e2cf87af93746d7c5e7964736f6c63430008110033","runtime-code":"0x608060405234801561001057600080fd5b50600436106100f55760003560e01c80639aaa182611610097578063d7a7a72c11610066578063d7a7a72c14610258578063e948e6001461026b578063edaa471d1461027e578063f8cb79431461029157600080fd5b80639aaa1826146101f7578063aae6d8841461021f578063c2e9e20814610232578063cb3eb0e11461024557600080fd5b80634e765004116100d35780634e7650041461016b5780635a0ca172146101935780635fed0261146101c357806360cf3bf0146101d657600080fd5b8063137e618a146100fa57806317ebb0b7146101225780631c9aa22214610142575b600080fd5b61010d610108366004610c10565b6102a4565b60405190151581526020015b60405180910390f35b610135610130366004610cbe565b6102ca565b6040516101199190610d2b565b610155610150366004610d97565b61038d565b60405164ffffffffff9091168152602001610119565b61017e610179366004610d97565b6103a0565b60405163ffffffff9091168152602001610119565b6101a66101a1366004610d97565b6103b3565b6040516bffffffffffffffffffffffff9091168152602001610119565b6101356101d1366004610d97565b6103c6565b6101e96101e4366004610d97565b6103e5565b604051908152602001610119565b61020a610205366004610d97565b6103f8565b60408051928352602083019190915201610119565b61010d61022d366004610d97565b610415565b6101e9610240366004610d97565b610428565b61017e610253366004610d97565b61043b565b6101e9610266366004610d97565b61044e565b610155610279366004610d97565b610461565b6101e961028c366004610dcc565b610474565b6101e961029f366004610df8565b610480565b60006102c16102b28361053a565b6102bb8561053a565b9061054d565b90505b92915050565b60408051602081018890527fffffffff0000000000000000000000000000000000000000000000000000000060e088811b82168385015287901b1660448201527fffffffffff00000000000000000000000000000000000000000000000000000060d886811b8216604884015285901b16604d8201527fffffffffffffffffffffffff000000000000000000000000000000000000000060a084901b1660528201528151808203603e018152605e9091019091526060905b979650505050505050565b60006102c461039b8361053a565b61056e565b60006102c46103ae8361053a565b610580565b60006102c46103c18361053a565b61058f565b606060006103d38361053a565b90506103de816105a4565b9392505050565b60006102c46103f38361053a565b610601565b60008061040c6104078461053a565b61062d565b91509150915091565b60006102c461042383610657565b610672565b60006102c46104368361053a565b61069a565b60006102c46104498361053a565b6106a8565b60006102c461045c8361053a565b6106b7565b60006102c461046f8361053a565b6106f6565b60006102c18383610705565b604080517fffffffff0000000000000000000000000000000000000000000000000000000060e087901b166020808301919091527fffffffffff00000000000000000000000000000000000000000000000000000060d887811b8216602485015286901b1660298301527fffffffffffffffffffffffff000000000000000000000000000000000000000060a085901b16602e8301528251808303601a018152603a90920190925280519101206000905b95945050505050565b60006102c461054883610657565b610766565b600061055d826107ab565b6107ab565b610566846107ab565b149392505050565b60006102c4602d6005845b91906107d6565b60006102c46024600484610579565b60006102c46105a16032600c85610579565b90565b604051806105b583602083016107f7565b506fffffffffffffffffffffffffffffffff83166000601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168301602001604052509052919050565b60006102c4827f43713cd927f8eb63b519f3b180bd5f3708ebbe93666be9ba4b9624b7bc57e6636108a0565b6000808261063f6105588260246108c3565b925061064f6105588260246108d0565b915050915091565b80516000906020830161066a8183610932565b949350505050565b6000610680600c6032610e4c565b6fffffffffffffffffffffffffffffffff83161492915050565b60006102c482826020610995565b60006102c46020600484610579565b60008060006106c58461062d565b6040805160208082019490945280820192909252805180830382018152606090920190528051910120949350505050565b60006102c46028600584610579565b6000828260405160200161074892919091825260e01b7fffffffff0000000000000000000000000000000000000000000000000000000016602082015260240190565b60405160208183030381529060405280519060200120905092915050565b600061077182610672565b6107a7576040517f6ba041c400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5090565b6000806107b88360801c90565b6fffffffffffffffffffffffffffffffff9390931690922092915050565b6000806107e4858585610995565b602084900360031b1c9150509392505050565b6040516000906fffffffffffffffffffffffffffffffff841690608085901c9080851015610851576040517f4b2a158c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008386858560045afa905080610894576040517f7c7d772f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b608086901b8417610382565b6000816108ac846107ab565b604080516020810193909352820152606001610748565b60006102c1838284610a9f565b60006fffffffffffffffffffffffffffffffff83168083111561091f576040517fa3b99ded00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61066a8361092d8660801c90565b018483035b60008061093f8385610e4c565b905060405181111561094f575060005b80600003610989576040517f10bef38600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b608084901b831761066a565b6000816000036109a7575060006103de565b60208211156109e2576040517f31d784a800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6fffffffffffffffffffffffffffffffff84166109ff8385610e4c565b1115610a37576040517fa3b99ded00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600382901b6000610a488660801c90565b909401517f80000000000000000000000000000000000000000000000000000000000000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff929092019190911d16949350505050565b600080610aac8560801c90565b9050610ab785610b10565b83610ac28684610e4c565b610acc9190610e4c565b1115610b04576040517fa3b99ded00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61053184820184610932565b60006fffffffffffffffffffffffffffffffff8216610b2f8360801c90565b0192915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f830112610b7657600080fd5b813567ffffffffffffffff80821115610b9157610b91610b36565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715610bd757610bd7610b36565b81604052838152866020858801011115610bf057600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060408385031215610c2357600080fd5b823567ffffffffffffffff80821115610c3b57600080fd5b610c4786838701610b65565b93506020850135915080821115610c5d57600080fd5b50610c6a85828601610b65565b9150509250929050565b803563ffffffff81168114610c8857600080fd5b919050565b803564ffffffffff81168114610c8857600080fd5b80356bffffffffffffffffffffffff81168114610c8857600080fd5b60008060008060008060c08789031215610cd757600080fd5b86359550610ce760208801610c74565b9450610cf560408801610c74565b9350610d0360608801610c8d565b9250610d1160808801610c8d565b9150610d1f60a08801610ca2565b90509295509295509295565b600060208083528351808285015260005b81811015610d5857858101830151858201604001528201610d3c565b5060006040828601015260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8301168501019250505092915050565b600060208284031215610da957600080fd5b813567ffffffffffffffff811115610dc057600080fd5b61066a84828501610b65565b60008060408385031215610ddf57600080fd5b82359150610def60208401610c74565b90509250929050565b60008060008060808587031215610e0e57600080fd5b610e1785610c74565b9350610e2560208601610c8d565b9250610e3360408601610c8d565b9150610e4160608601610ca2565b905092959194509250565b808201808211156102c4577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fdfea2646970667358221220d6e0381525b771a3cf213697c3ed8c03476e756a5ba6e2cf87af93746d7c5e7964736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17;\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// contracts/libs/memory/MemView.sol\n\n/// @dev MemView is an untyped view over a portion of memory to be used instead of `bytes memory`\ntype MemView is uint256;\n\n/// @dev Attach library functions to MemView\nusing MemViewLib for MemView global;\n\n/// @notice Library for operations with the memory views.\n/// Forked from https://github.com/summa-tx/memview-sol with several breaking changes:\n/// - The codebase is ported to Solidity 0.8\n/// - Custom errors are added\n/// - The runtime type checking is replaced with compile-time check provided by User-Defined Value Types\n/// https://docs.soliditylang.org/en/latest/types.html#user-defined-value-types\n/// - uint256 is used as the underlying type for the \"memory view\" instead of bytes29.\n/// It is wrapped into MemView custom type in order not to be confused with actual integers.\n/// - Therefore the \"type\" field is discarded, allowing to allocate 16 bytes for both view location and length\n/// - The documentation is expanded\n/// - Library functions unused by the rest of the codebase are removed\n// - Very pretty code separators are added :)\nlibrary MemViewLib {\n /// @notice Stack layout for uint256 (from highest bits to lowest)\n /// (32 .. 16] loc 16 bytes Memory address of underlying bytes\n /// (16 .. 00] len 16 bytes Length of underlying bytes\n\n // ═══════════════════════════════════════════ BUILDING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Instantiate a new untyped memory view. This should generally not be called directly.\n * Prefer `ref` wherever possible.\n * @param loc_ The memory address\n * @param len_ The length\n * @return The new view with the specified location and length\n */\n function build(uint256 loc_, uint256 len_) internal pure returns (MemView) {\n uint256 end_ = loc_ + len_;\n // Make sure that a view is not constructed that points to unallocated memory\n // as this could be indicative of a buffer overflow attack\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n if gt(end_, mload(0x40)) { end_ := 0 }\n }\n if (end_ == 0) {\n revert UnallocatedMemory();\n }\n return _unsafeBuildUnchecked(loc_, len_);\n }\n\n /**\n * @notice Instantiate a memory view from a byte array.\n * @dev Note that due to Solidity memory representation, it is not possible to\n * implement a deref, as the `bytes` type stores its len in memory.\n * @param arr The byte array\n * @return The memory view over the provided byte array\n */\n function ref(bytes memory arr) internal pure returns (MemView) {\n uint256 len_ = arr.length;\n // `bytes arr` is stored in memory in the following way\n // 1. First, uint256 arr.length is stored. That requires 32 bytes (0x20).\n // 2. Then, the array data is stored.\n uint256 loc_;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // We add 0x20, so that the view starts exactly where the array data starts\n loc_ := add(arr, 0x20)\n }\n return build(loc_, len_);\n }\n\n // ════════════════════════════════════════════ CLONING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Copies the referenced memory to a new loc in memory, returning a `bytes` pointing to the new memory.\n * @param memView The memory view\n * @return arr The cloned byte array\n */\n function clone(MemView memView) internal view returns (bytes memory arr) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n // This is where the byte array will be stored\n arr := ptr\n }\n unchecked {\n _unsafeCopyTo(memView, ptr + 0x20);\n }\n // `bytes arr` is stored in memory in the following way\n // 1. First, uint256 arr.length is stored. That requires 32 bytes (0x20).\n // 2. Then, the array data is stored.\n uint256 len_ = memView.len();\n uint256 footprint_ = memView.footprint();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Write new unused pointer: the old value + array footprint + 32 bytes to store the length\n mstore(0x40, add(add(ptr, footprint_), 0x20))\n // Write len of new array (in bytes)\n mstore(ptr, len_)\n }\n }\n\n /**\n * @notice Copies all views, joins them into a new bytearray.\n * @param memViews The memory views\n * @return arr The new byte array with joined data behind the given views\n */\n function join(MemView[] memory memViews) internal view returns (bytes memory arr) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n // This is where the byte array will be stored\n arr := ptr\n }\n MemView newView;\n unchecked {\n newView = _unsafeJoin(memViews, ptr + 0x20);\n }\n uint256 len_ = newView.len();\n uint256 footprint_ = newView.footprint();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Write new unused pointer: the old value + array footprint + 32 bytes to store the length\n mstore(0x40, add(add(ptr, footprint_), 0x20))\n // Write len of new array (in bytes)\n mstore(ptr, len_)\n }\n }\n\n // ══════════════════════════════════════════ INSPECTING MEMORY VIEW ═══════════════════════════════════════════════\n\n /**\n * @notice Returns the memory address of the underlying bytes.\n * @param memView The memory view\n * @return loc_ The memory address\n */\n function loc(MemView memView) internal pure returns (uint256 loc_) {\n // loc is stored in the highest 16 bytes of the underlying uint256\n return MemView.unwrap(memView) \u003e\u003e 128;\n }\n\n /**\n * @notice Returns the number of bytes of the view.\n * @param memView The memory view\n * @return len_ The length of the view\n */\n function len(MemView memView) internal pure returns (uint256 len_) {\n // len is stored in the lowest 16 bytes of the underlying uint256\n return MemView.unwrap(memView) \u0026 type(uint128).max;\n }\n\n /**\n * @notice Returns the endpoint of `memView`.\n * @param memView The memory view\n * @return end_ The endpoint of `memView`\n */\n function end(MemView memView) internal pure returns (uint256 end_) {\n // The endpoint never overflows uint128, let alone uint256, so we could use unchecked math here\n unchecked {\n return memView.loc() + memView.len();\n }\n }\n\n /**\n * @notice Returns the number of memory words this memory view occupies, rounded up.\n * @param memView The memory view\n * @return words_ The number of memory words\n */\n function words(MemView memView) internal pure returns (uint256 words_) {\n // returning ceil(length / 32.0)\n unchecked {\n return (memView.len() + 31) \u003e\u003e 5;\n }\n }\n\n /**\n * @notice Returns the in-memory footprint of a fresh copy of the view.\n * @param memView The memory view\n * @return footprint_ The in-memory footprint of a fresh copy of the view.\n */\n function footprint(MemView memView) internal pure returns (uint256 footprint_) {\n // words() * 32\n return memView.words() \u003c\u003c 5;\n }\n\n // ════════════════════════════════════════════ HASHING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Returns the keccak256 hash of the underlying memory\n * @param memView The memory view\n * @return digest The keccak256 hash of the underlying memory\n */\n function keccak(MemView memView) internal pure returns (bytes32 digest) {\n uint256 loc_ = memView.loc();\n uint256 len_ = memView.len();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n digest := keccak256(loc_, len_)\n }\n }\n\n /**\n * @notice Adds a salt to the keccak256 hash of the underlying data and returns the keccak256 hash of the\n * resulting data.\n * @param memView The memory view\n * @return digestSalted keccak256(salt, keccak256(memView))\n */\n function keccakSalted(MemView memView, bytes32 salt) internal pure returns (bytes32 digestSalted) {\n return keccak256(bytes.concat(salt, memView.keccak()));\n }\n\n // ════════════════════════════════════════════ SLICING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Safe slicing without memory modification.\n * @param memView The memory view\n * @param index_ The start index\n * @param len_ The length\n * @return The new view for the slice of the given length starting from the given index\n */\n function slice(MemView memView, uint256 index_, uint256 len_) internal pure returns (MemView) {\n uint256 loc_ = memView.loc();\n // Ensure it doesn't overrun the view\n if (loc_ + index_ + len_ \u003e memView.end()) {\n revert ViewOverrun();\n }\n // Build a view starting from index with the given length\n unchecked {\n // loc_ + index_ \u003c= memView.end()\n return build({loc_: loc_ + index_, len_: len_});\n }\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing bytes from `index` to end(memView).\n * @param memView The memory view\n * @param index_ The start index\n * @return The new view for the slice starting from the given index until the initial view endpoint\n */\n function sliceFrom(MemView memView, uint256 index_) internal pure returns (MemView) {\n uint256 len_ = memView.len();\n // Ensure it doesn't overrun the view\n if (index_ \u003e len_) {\n revert ViewOverrun();\n }\n // Build a view starting from index with the given length\n unchecked {\n // index_ \u003c= len_ =\u003e memView.loc() + index_ \u003c= memView.loc() + memView.len() == memView.end()\n return build({loc_: memView.loc() + index_, len_: len_ - index_});\n }\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing the first `len` bytes.\n * @param memView The memory view\n * @param len_ The length\n * @return The new view for the slice of the given length starting from the initial view beginning\n */\n function prefix(MemView memView, uint256 len_) internal pure returns (MemView) {\n return memView.slice({index_: 0, len_: len_});\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing the last `len` byte.\n * @param memView The memory view\n * @param len_ The length\n * @return The new view for the slice of the given length until the initial view endpoint\n */\n function postfix(MemView memView, uint256 len_) internal pure returns (MemView) {\n uint256 viewLen = memView.len();\n // Ensure it doesn't overrun the view\n if (len_ \u003e viewLen) {\n revert ViewOverrun();\n }\n // Could do the unchecked math due to the check above\n uint256 index_;\n unchecked {\n index_ = viewLen - len_;\n }\n // Build a view starting from index with the given length\n unchecked {\n // len_ \u003c= memView.len() =\u003e memView.loc() \u003c= loc_ \u003c= memView.end()\n return build({loc_: memView.loc() + viewLen - len_, len_: len_});\n }\n }\n\n // ═══════════════════════════════════════════ INDEXING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Load up to 32 bytes from the view onto the stack.\n * @dev Returns a bytes32 with only the `bytes_` HIGHEST bytes set.\n * This can be immediately cast to a smaller fixed-length byte array.\n * To automatically cast to an integer, use `indexUint`.\n * @param memView The memory view\n * @param index_ The index\n * @param bytes_ The amount of bytes to load onto the stack\n * @return result The 32 byte result having only `bytes_` highest bytes set\n */\n function index(MemView memView, uint256 index_, uint256 bytes_) internal pure returns (bytes32 result) {\n if (bytes_ == 0) {\n return bytes32(0);\n }\n // Can't load more than 32 bytes to the stack in one go\n if (bytes_ \u003e 32) {\n revert IndexedTooMuch();\n }\n // The last indexed byte should be within view boundaries\n if (index_ + bytes_ \u003e memView.len()) {\n revert ViewOverrun();\n }\n uint256 bitLength = bytes_ \u003c\u003c 3; // bytes_ * 8\n uint256 loc_ = memView.loc();\n // Get a mask with `bitLength` highest bits set\n uint256 mask;\n // 0x800...00 binary representation is 100...00\n // sar stands for \"signed arithmetic shift\": https://en.wikipedia.org/wiki/Arithmetic_shift\n // sar(N-1, 100...00) = 11...100..00, with exactly N highest bits set to 1\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n mask := sar(sub(bitLength, 1), 0x8000000000000000000000000000000000000000000000000000000000000000)\n }\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load a full word using index offset, and apply mask to ignore non-relevant bytes\n result := and(mload(add(loc_, index_)), mask)\n }\n }\n\n /**\n * @notice Parse an unsigned integer from the view at `index`.\n * @dev Requires that the view have \u003e= `bytes_` bytes following that index.\n * @param memView The memory view\n * @param index_ The index\n * @param bytes_ The amount of bytes to load onto the stack\n * @return The unsigned integer\n */\n function indexUint(MemView memView, uint256 index_, uint256 bytes_) internal pure returns (uint256) {\n bytes32 indexedBytes = memView.index(index_, bytes_);\n // `index()` returns left-aligned `bytes_`, while integers are right-aligned\n // Shifting here to right-align with the full 32 bytes word: need to shift right `(32 - bytes_)` bytes\n unchecked {\n // memView.index() reverts when bytes_ \u003e 32, thus unchecked math\n return uint256(indexedBytes) \u003e\u003e ((32 - bytes_) \u003c\u003c 3);\n }\n }\n\n /**\n * @notice Parse an address from the view at `index`.\n * @dev Requires that the view have \u003e= 20 bytes following that index.\n * @param memView The memory view\n * @param index_ The index\n * @return The address\n */\n function indexAddress(MemView memView, uint256 index_) internal pure returns (address) {\n // index 20 bytes as `uint160`, and then cast to `address`\n return address(uint160(memView.indexUint(index_, 20)));\n }\n\n // ══════════════════════════════════════════════ PRIVATE HELPERS ══════════════════════════════════════════════════\n\n /// @dev Returns a memory view over the specified memory location\n /// without checking if it points to unallocated memory.\n function _unsafeBuildUnchecked(uint256 loc_, uint256 len_) private pure returns (MemView) {\n // There is no scenario where loc or len would overflow uint128, so we omit this check.\n // We use the highest 128 bits to encode the location and the lowest 128 bits to encode the length.\n return MemView.wrap((loc_ \u003c\u003c 128) | len_);\n }\n\n /**\n * @notice Copy the view to a location, return an unsafe memory reference\n * @dev Super Dangerous direct memory access.\n * This reference can be overwritten if anything else modifies memory (!!!).\n * As such it MUST be consumed IMMEDIATELY. Update the free memory pointer to ensure the copied data\n * is not overwritten. This function is private to prevent unsafe usage by callers.\n * @param memView The memory view\n * @param newLoc The new location to copy the underlying view data\n * @return The memory view over the unsafe memory with the copied underlying data\n */\n function _unsafeCopyTo(MemView memView, uint256 newLoc) private view returns (MemView) {\n uint256 len_ = memView.len();\n uint256 oldLoc = memView.loc();\n\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n }\n // Revert if we're writing in occupied memory\n if (newLoc \u003c ptr) {\n revert OccupiedMemory();\n }\n bool res;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // use the identity precompile (0x04) to copy\n res := staticcall(gas(), 0x04, oldLoc, len_, newLoc, len_)\n }\n if (!res) revert PrecompileOutOfGas();\n return _unsafeBuildUnchecked({loc_: newLoc, len_: len_});\n }\n\n /**\n * @notice Join the views in memory, return an unsafe reference to the memory.\n * @dev Super Dangerous direct memory access.\n * This reference can be overwritten if anything else modifies memory (!!!).\n * As such it MUST be consumed IMMEDIATELY. Update the free memory pointer to ensure the copied data\n * is not overwritten. This function is private to prevent unsafe usage by callers.\n * @param memViews The memory views\n * @return The conjoined view pointing to the new memory\n */\n function _unsafeJoin(MemView[] memory memViews, uint256 location) private view returns (MemView) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n }\n // Revert if we're writing in occupied memory\n if (location \u003c ptr) {\n revert OccupiedMemory();\n }\n // Copy the views to the specified location one by one, by tracking the amount of copied bytes so far\n uint256 offset = 0;\n for (uint256 i = 0; i \u003c memViews.length;) {\n MemView memView = memViews[i];\n // We can use the unchecked math here as location + sum(view.length) will never overflow uint256\n unchecked {\n _unsafeCopyTo(memView, location + offset);\n offset += memView.len();\n ++i;\n }\n }\n return _unsafeBuildUnchecked({loc_: location, len_: offset});\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// contracts/libs/memory/State.sol\n\n/// State is a memory view over a formatted state payload.\ntype State is uint256;\n\nusing StateLib for State global;\n\n/// # State\n/// State structure represents the state of Origin contract at some point of time.\n/// - State is structured in a way to track the updates of the Origin Merkle Tree.\n/// - State includes root of the Origin Merkle Tree, origin domain and some additional metadata.\n/// ## Origin Merkle Tree\n/// Hash of every sent message is inserted in the Origin Merkle Tree, which changes\n/// the value of Origin Merkle Root (which is the root for the mentioned tree).\n/// - Origin has a single Merkle Tree for all messages, regardless of their destination domain.\n/// - This leads to Origin state being updated if and only if a message was sent in a block.\n/// - Origin contract is a \"source of truth\" for states: a state is considered \"valid\" in its Origin,\n/// if it matches the state of the Origin contract after the N-th (nonce) message was sent.\n///\n/// # Memory layout of State fields\n///\n/// | Position | Field | Type | Bytes | Description |\n/// | ---------- | ----------- | ------- | ----- | ------------------------------ |\n/// | [000..032) | root | bytes32 | 32 | Root of the Origin Merkle Tree |\n/// | [032..036) | origin | uint32 | 4 | Domain where Origin is located |\n/// | [036..040) | nonce | uint32 | 4 | Amount of sent messages |\n/// | [040..045) | blockNumber | uint40 | 5 | Block of last sent message |\n/// | [045..050) | timestamp | uint40 | 5 | Time of last sent message |\n/// | [050..062) | gasData | uint96 | 12 | Gas data for the chain |\n///\n/// @dev State could be used to form a Snapshot to be signed by a Guard or a Notary.\nlibrary StateLib {\n using MemViewLib for bytes;\n\n /// @dev The variables below are not supposed to be used outside of the library directly.\n uint256 private constant OFFSET_ROOT = 0;\n uint256 private constant OFFSET_ORIGIN = 32;\n uint256 private constant OFFSET_NONCE = 36;\n uint256 private constant OFFSET_BLOCK_NUMBER = 40;\n uint256 private constant OFFSET_TIMESTAMP = 45;\n uint256 private constant OFFSET_GAS_DATA = 50;\n\n // ═══════════════════════════════════════════════════ STATE ═══════════════════════════════════════════════════════\n\n /**\n * @notice Returns a formatted State payload with provided fields\n * @param root_ New merkle root\n * @param origin_ Domain of Origin's chain\n * @param nonce_ Nonce of the merkle root\n * @param blockNumber_ Block number when root was saved in Origin\n * @param timestamp_ Block timestamp when root was saved in Origin\n * @param gasData_ Gas data for the chain\n * @return Formatted state\n */\n function formatState(\n bytes32 root_,\n uint32 origin_,\n uint32 nonce_,\n uint40 blockNumber_,\n uint40 timestamp_,\n GasData gasData_\n ) internal pure returns (bytes memory) {\n return abi.encodePacked(root_, origin_, nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n /**\n * @notice Returns a State view over the given payload.\n * @dev Will revert if the payload is not a state.\n */\n function castToState(bytes memory payload) internal pure returns (State) {\n return castToState(payload.ref());\n }\n\n /**\n * @notice Casts a memory view to a State view.\n * @dev Will revert if the memory view is not over a state.\n */\n function castToState(MemView memView) internal pure returns (State) {\n if (!isState(memView)) revert UnformattedState();\n return State.wrap(MemView.unwrap(memView));\n }\n\n /// @notice Checks that a payload is a formatted State.\n function isState(MemView memView) internal pure returns (bool) {\n return memView.len() == STATE_LENGTH;\n }\n\n /// @notice Returns the hash of a State, that could be later signed by a Guard to signal\n /// that the state is invalid.\n function hashInvalid(State state) internal pure returns (bytes32) {\n // The final hash to sign is keccak(stateInvalidSalt, keccak(state))\n return state.unwrap().keccakSalted(STATE_INVALID_SALT);\n }\n\n /// @notice Convenience shortcut for unwrapping a view.\n function unwrap(State state) internal pure returns (MemView) {\n return MemView.wrap(State.unwrap(state));\n }\n\n /// @notice Compares two State structures.\n function equals(State a, State b) internal pure returns (bool) {\n // Length of a State payload is fixed, so we just need to compare the hashes\n return a.unwrap().keccak() == b.unwrap().keccak();\n }\n\n // ═══════════════════════════════════════════════ STATE HASHING ═══════════════════════════════════════════════════\n\n /// @notice Returns the hash of the State.\n /// @dev We are using the Merkle Root of a tree with two leafs (see below) as state hash.\n function leaf(State state) internal pure returns (bytes32) {\n (bytes32 leftLeaf_, bytes32 rightLeaf_) = state.subLeafs();\n // Final hash is the parent of these leafs\n return keccak256(bytes.concat(leftLeaf_, rightLeaf_));\n }\n\n /// @notice Returns \"sub-leafs\" of the State. Hash of these \"sub leafs\" is going to be used\n /// as a \"state leaf\" in the \"Snapshot Merkle Tree\".\n /// This enables proving that leftLeaf = (root, origin) was a part of the \"Snapshot Merkle Tree\",\n /// by combining `rightLeaf` with the remainder of the \"Snapshot Merkle Proof\".\n function subLeafs(State state) internal pure returns (bytes32 leftLeaf_, bytes32 rightLeaf_) {\n MemView memView = state.unwrap();\n // Left leaf is (root, origin)\n leftLeaf_ = memView.prefix({len_: OFFSET_NONCE}).keccak();\n // Right leaf is (metadata), or (nonce, blockNumber, timestamp)\n rightLeaf_ = memView.sliceFrom({index_: OFFSET_NONCE}).keccak();\n }\n\n /// @notice Returns the left \"sub-leaf\" of the State.\n function leftLeaf(bytes32 root_, uint32 origin_) internal pure returns (bytes32) {\n // We use encodePacked here to simulate the State memory layout\n return keccak256(abi.encodePacked(root_, origin_));\n }\n\n /// @notice Returns the right \"sub-leaf\" of the State.\n function rightLeaf(uint32 nonce_, uint40 blockNumber_, uint40 timestamp_, GasData gasData_)\n internal\n pure\n returns (bytes32)\n {\n // We use encodePacked here to simulate the State memory layout\n return keccak256(abi.encodePacked(nonce_, blockNumber_, timestamp_, gasData_));\n }\n\n // ═══════════════════════════════════════════════ STATE SLICING ═══════════════════════════════════════════════════\n\n /// @notice Returns a historical Merkle root from the Origin contract.\n function root(State state) internal pure returns (bytes32) {\n return state.unwrap().index({index_: OFFSET_ROOT, bytes_: 32});\n }\n\n /// @notice Returns domain of chain where the Origin contract is deployed.\n function origin(State state) internal pure returns (uint32) {\n // Can be safely casted to uint32, since we index 4 bytes\n return uint32(state.unwrap().indexUint({index_: OFFSET_ORIGIN, bytes_: 4}));\n }\n\n /// @notice Returns nonce of Origin contract at the time, when `root` was the Merkle root.\n function nonce(State state) internal pure returns (uint32) {\n // Can be safely casted to uint32, since we index 4 bytes\n return uint32(state.unwrap().indexUint({index_: OFFSET_NONCE, bytes_: 4}));\n }\n\n /// @notice Returns a block number when `root` was saved in Origin.\n function blockNumber(State state) internal pure returns (uint40) {\n // Can be safely casted to uint40, since we index 5 bytes\n return uint40(state.unwrap().indexUint({index_: OFFSET_BLOCK_NUMBER, bytes_: 5}));\n }\n\n /// @notice Returns a block timestamp when `root` was saved in Origin.\n /// @dev This is the timestamp according to the origin chain.\n function timestamp(State state) internal pure returns (uint40) {\n // Can be safely casted to uint40, since we index 5 bytes\n return uint40(state.unwrap().indexUint({index_: OFFSET_TIMESTAMP, bytes_: 5}));\n }\n\n /// @notice Returns gas data for the chain.\n function gasData(State state) internal pure returns (GasData) {\n return GasDataLib.wrapGasData(state.unwrap().indexUint({index_: OFFSET_GAS_DATA, bytes_: GAS_DATA_LENGTH}));\n }\n}\n\n// test/harnesses/libs/memory/StateHarness.t.sol\n\n// solhint-disable ordering\n/// @notice Exposes State methods for testing against golang.\ncontract StateHarness {\n using StateLib for bytes;\n using StateLib for MemView;\n using MemViewLib for bytes;\n\n // Note: we don't add an empty test() function here, as it currently leads\n // to zero coverage on the corresponding library.\n\n // ══════════════════════════════════════════════════ GETTERS ══════════════════════════════════════════════════════\n\n function castToState(bytes memory payload) public view returns (bytes memory) {\n // Walkaround to get the forge coverage working on libraries, see\n // https://github.com/foundry-rs/foundry/pull/3128#issuecomment-1241245086\n State state = StateLib.castToState(payload);\n return state.unwrap().clone();\n }\n\n function equals(bytes memory a, bytes memory b) public pure returns (bool) {\n return a.castToState().equals(b.castToState());\n }\n\n function hashInvalid(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().hashInvalid();\n }\n\n function leaf(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().leaf();\n }\n\n function subLeafs(bytes memory payload) public pure returns (bytes32, bytes32) {\n return payload.castToState().subLeafs();\n }\n\n function leftLeaf(bytes32 root_, uint32 origin_) public pure returns (bytes32) {\n return StateLib.leftLeaf(root_, origin_);\n }\n\n function rightLeaf(uint32 nonce_, uint40 blockNumber_, uint40 timestamp_, GasData gasData_)\n public\n pure\n returns (bytes32)\n {\n return StateLib.rightLeaf(nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n function root(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().root();\n }\n\n function origin(bytes memory payload) public pure returns (uint32) {\n return payload.castToState().origin();\n }\n\n function nonce(bytes memory payload) public pure returns (uint32) {\n return payload.castToState().nonce();\n }\n\n function blockNumber(bytes memory payload) public pure returns (uint40) {\n return payload.castToState().blockNumber();\n }\n\n function timestamp(bytes memory payload) public pure returns (uint40) {\n return payload.castToState().timestamp();\n }\n\n function gasData(bytes memory payload) public pure returns (GasData) {\n return payload.castToState().gasData();\n }\n\n // ════════════════════════════════════════════════ FORMATTERS ═════════════════════════════════════════════════════\n\n function formatState(\n bytes32 root_,\n uint32 origin_,\n uint32 nonce_,\n uint40 blockNumber_,\n uint40 timestamp_,\n GasData gasData_\n ) public pure returns (bytes memory) {\n return StateLib.formatState(root_, origin_, nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n function isState(bytes memory payload) public pure returns (bool) {\n return payload.ref().isState();\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":"53868:3397:0:-:0;;;;;;;;;;;;;;;;;;;","srcMapRuntime":"53868:3397:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;54795:138;;;;;;:::i;:::-;;:::i;:::-;;;1694:14:1;;1687:22;1669:41;;1657:2;1642:18;54795:138:0;;;;;;;;56826:318;;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;56239:127::-;;;;;;:::i;:::-;;:::i;:::-;;;3973:12:1;3961:25;;;3943:44;;3931:2;3916:18;56239:127:0;3799:194:1;55977:119:0;;;;;;:::i;:::-;;:::i;:::-;;;4172:10:1;4160:23;;;4142:42;;4130:2;4115:18;55977:119:0;3998:192:1;56372:124:0;;;;;;:::i;:::-;;:::i;:::-;;;4398:26:1;4386:39;;;4368:58;;4356:2;4341:18;56372:124:0;4195:237:1;54455:334:0;;;;;;:::i;:::-;;:::i;54939:132::-;;;;;;:::i;:::-;;:::i;:::-;;;4583:25:1;;;4571:2;4556:18;54939:132:0;4437:177:1;55201:135:0;;;;;;:::i;:::-;;:::i;:::-;;;;4793:25:1;;;4849:2;4834:18;;4827:34;;;;4766:18;55201:135:0;4619:248:1;57150:113:0;;;;;;:::i;:::-;;:::i;55726:118::-;;;;;;:::i;:::-;;:::i;55850:121::-;;;;;;:::i;:::-;;:::i;55077:118::-;;;;;;:::i;:::-;;:::i;56102:131::-;;;;;;:::i;:::-;;:::i;55342:136::-;;;;;;:::i;:::-;;:::i;55484:236::-;;;;;;:::i;:::-;;:::i;54795:138::-;54864:4;54887:39;54910:15;:1;:13;:15::i;:::-;54887;:1;:13;:15::i;:::-;:22;;:39::i;:::-;54880:46;;54795:138;;;;;:::o;56826:318::-;47883:76;;;;;;5874:19:1;;;5912:66;6016:3;6012:16;;;6008:25;;5994:12;;;5987:47;6068:16;;;6064:25;6050:12;;;6043:47;6109:66;6213:3;6209:16;;;6205:25;;6191:12;;;6184:47;6265:16;;;6261:25;6247:12;;;6240:47;6339:66;6325:3;6321:16;;;6317:89;6303:12;;;6296:111;47883:76:0;;;;;;;;;6423:12:1;;;;47883:76:0;;;57026:12;;57057:80;57050:87;56826:318;-1:-1:-1;;;;;;;56826:318:0:o;56239:127::-;56301:6;56326:33;:21;:7;:19;:21::i;:::-;:31;:33::i;55977:119::-;56035:6;56060:29;:21;:7;:19;:21::i;:::-;:27;:29::i;56372:124::-;56432:7;56458:31;:21;:7;:19;:21::i;:::-;:29;:31::i;54455:334::-;54519:12;54700:11;54714:29;54735:7;54714:20;:29::i;:::-;54700:43;-1:-1:-1;54760:22:0;54700:43;54760:20;:22::i;:::-;54753:29;54455:334;-1:-1:-1;;;54455:334:0:o;54939:132::-;55003:7;55029:35;:21;:7;:19;:21::i;:::-;:33;:35::i;55201:135::-;55262:7;55271;55297:32;:21;:7;:19;:21::i;:::-;:30;:32::i;:::-;55290:39;;;;55201:135;;;:::o;57150:113::-;57210:4;57233:23;:13;:7;:11;:13::i;:::-;:21;:23::i;55726:118::-;55783:7;55809:28;:21;:7;:19;:21::i;:::-;:26;:28::i;55850:121::-;55909:6;55934:30;:21;:7;:19;:21::i;:::-;:28;:30::i;55077:118::-;55134:7;55160:28;:21;:7;:19;:21::i;:::-;:26;:28::i;56102:131::-;56166:6;56191:35;:21;:7;:19;:21::i;:::-;:33;:35::i;55342:136::-;55412:7;55438:33;55456:5;55463:7;55438:17;:33::i;55484:236::-;51581:60;;;7583:66:1;7569:3;7565:16;;;7561:89;51581:60:0;;;;7549:102:1;;;;7670:66;7773:3;7769:16;;;7765:25;;7752:11;;;7745:46;7824:16;;;7820:25;7807:11;;;7800:46;7898:66;7884:3;7880:16;;;7876:89;7862:12;;;7855:111;51581:60:0;;;;;;;;;7982:12:1;;;;51581:60:0;;;51571:71;;;;;55621:7;;55651:62;55644:69;55484:236;-1:-1:-1;;;;;55484:236:0:o;48103:123::-;48169:5;48193:26;48205:13;:7;:11;:13::i;:::-;48193:11;:26::i;49316:214::-;49373:4;49504:19;:1;:17;:19::i;:10::-;:17;:19::i;:::-;49481;:1;49504:17;:19::i;49481:::-;:42;;49316:214;-1:-1:-1;;;49316:214:0:o;53260:224::-;53315:6;53413:63;46793:2;53473:1;53413:5;:14;:24;:63;:24;:63::i;52590:216::-;52641:6;52739:59;46686:2;52795:1;52739:5;:14;49145:118;53538:186;53591:7;53617:100;53640:76;46844:2;1141;53640:5;:14;49145:118;53640:76;49249:5;49145:118;18625:1041;18871:4;18865:11;;19001:34;19015:7;19030:4;19024:10;;19001:13;:34::i;:::-;-1:-1:-1;21811:17:0;21785:43;;19247:12;22643:2;22627:18;;23011:20;;19543;;19565:4;19539:31;19533:4;19526:45;-1:-1:-1;19633:17:0;;18625:1041;;-1:-1:-1;18625:1041:0:o;48865:214::-;48922:7;49025:47;:5;3030:31;49025:27;:47::i;50588:393::-;50642:17;;50709:5;50784:45;:36;50709:5;46686:2;50784:14;:36::i;:45::-;50772:57;-1:-1:-1;50924:50:0;:41;:7;46686:2;50924:17;:41::i;:50::-;50911:63;;50681:300;50588:393;;;:::o;17518:569::-;17606:10;;17572:7;;18032:4;18023:14;;18063:17;18023:14;17606:10;18063:5;:17::i;:::-;18056:24;17518:569;-1:-1:-1;;;;17518:569:0:o;48615:116::-;48672:4;1421:20;1141:2;1421;:20;:::i;:::-;21811:17;21785:43;;48695:29;;48615:116;-1:-1:-1;;48615:116:0:o;52048:138::-;52098:7;52124:55;:5;52098:7;52175:2;52124:20;:55::i;52271:218::-;52323:6;52421:60;46638:2;52478:1;52421:5;:14;49145:118;49995:248;50045:7;50065:17;50084:18;50106:16;:5;:14;:16::i;:::-;50200:35;;;;;;;6887:19:1;;;;6922:12;;;6915:28;;;;50200:35:0;;;;;;;;;6959:12:1;;;;50200:35:0;;50190:46;;;;;;49995:248;-1:-1:-1;;;;49995:248:0:o;52884:229::-;52941:6;53039:66;46741:2;53102:1;53039:5;:14;49145:118;51045:220;51117:7;51242:5;51249:7;51225:32;;;;;;;;7137:19:1;;;7194:3;7190:16;7208:66;7186:89;7181:2;7172:12;;7165:111;7301:2;7292:12;;6982:328;51225:32:0;;;;;;;;;;;;;51215:43;;;;;;51208:50;;51045:220;;;;:::o;48364:185::-;48425:5;48447:16;48455:7;48447;:16::i;:::-;48442:48;;48472:18;;;;;;;;;;;;;;48442:48;-1:-1:-1;48533:7:0;48364:185::o;23549:292::-;23605:14;23631:12;23646:13;:7;21444:3;21417:30;;21258:196;23646:13;21811:17;21785:43;;;;23804:21;;;;;-1:-1:-1;;23549:292:0:o;30098:538::-;30189:7;;30231:29;:7;30245:6;30253;30231:13;:29::i;:::-;30601:2;:11;;;30617:1;30600:18;30574:45;;-1:-1:-1;;30098:538:0;;;;;:::o;32559:842::-;32898:4;32892:11;32637:7;;21811:17;21785:43;;;21444:3;21417:30;;;;32980:12;;;32976:66;;;33015:16;;;;;;;;;;;;;;32976:66;33051:8;33267:4;33259:6;33253:4;33245:6;33239:4;33232:5;33221:51;33214:58;;33296:3;33291:37;;33308:20;;;;;;;;;;;;;;33291:37;31908:3;31900:11;;;31899:20;;33345:49;31575:352;24104:169;24180:20;24242:4;24248:16;:7;:14;:16::i;:::-;24229:36;;;;;;6887:19:1;;;;6922:12;;6915:28;6959:12;;24229:36:0;6730:247:1;26493:141:0;26563:7;26589:38;:7;26563;26621:4;26589:13;:38::i;25672:529::-;25747:7;21811:17;21785:43;;25854:13;;;25850:64;;;25890:13;;;;;;;;;;;;;;25850:64;26126:58;26155:6;26139:13;:7;21444:3;21417:30;;21258:196;26139:13;:22;26176:6;26169:4;:13;16638:540;16704:7;;16738:11;16745:4;16738;:11;:::i;:::-;16723:26;;17017:4;17011:11;17005:4;17002:21;16999:38;;;-1:-1:-1;17034:1:0;16999:38;17060:4;17068:1;17060:9;17056:66;;17092:19;;;;;;;;;;;;;;17056:66;31908:3;31900:11;;;31899:20;;17138:33;31575:352;28406:1334;28493:14;28523:6;28533:1;28523:11;28519:59;;-1:-1:-1;28565:1:0;28550:17;;28519:59;28664:2;28655:6;:11;28651:65;;;28689:16;;;;;;;;;;;;;;28651:65;21811:17;21785:43;;28795:15;28804:6;28795;:15;:::i;:::-;:31;28791:82;;;28849:13;;;;;;;;;;;;;;28791:82;28912:1;28902:11;;;28882:17;28952:13;:7;21444:3;21417:30;;21258:196;28952:13;29699:17;;;29693:24;29410:66;29391:17;;;;;29387:90;;;;29689:35;;28406:1334;-1:-1:-1;;;;28406:1334:0:o;24877:484::-;24962:7;24981:12;24996:13;:7;21444:3;21417:30;;21258:196;24996:13;24981:28;;25092:13;:7;:11;:13::i;:::-;25085:4;25069:13;25076:6;25069:4;:13;:::i;:::-;:20;;;;:::i;:::-;:36;25065:87;;;25128:13;;;;;;;;;;;;;;25065:87;25304:40;25324:6;25317:4;:13;25338:4;25304:5;:40::i;22005:258::-;22058:12;21811:17;21785:43;;22217:13;:7;21444:3;21417:30;;21258:196;22217:13;:29;;22005:258;-1:-1:-1;;22005:258:0:o;14:184:1:-;66:77;63:1;56:88;163:4;160:1;153:15;187:4;184:1;177:15;203:777;245:5;298:3;291:4;283:6;279:17;275:27;265:55;;316:1;313;306:12;265:55;352:6;339:20;378:18;415:2;411;408:10;405:36;;;421:18;;:::i;:::-;555:2;549:9;617:4;609:13;;460:66;605:22;;;629:2;601:31;597:40;585:53;;;653:18;;;673:22;;;650:46;647:72;;;699:18;;:::i;:::-;739:10;735:2;728:22;774:2;766:6;759:18;820:3;813:4;808:2;800:6;796:15;792:26;789:35;786:55;;;837:1;834;827:12;786:55;901:2;894:4;886:6;882:17;875:4;867:6;863:17;850:54;948:1;941:4;936:2;928:6;924:15;920:26;913:37;968:6;959:15;;;;;;203:777;;;;:::o;985:539::-;1071:6;1079;1132:2;1120:9;1111:7;1107:23;1103:32;1100:52;;;1148:1;1145;1138:12;1100:52;1188:9;1175:23;1217:18;1258:2;1250:6;1247:14;1244:34;;;1274:1;1271;1264:12;1244:34;1297:49;1338:7;1329:6;1318:9;1314:22;1297:49;:::i;:::-;1287:59;;1399:2;1388:9;1384:18;1371:32;1355:48;;1428:2;1418:8;1415:16;1412:36;;;1444:1;1441;1434:12;1412:36;;1467:51;1510:7;1499:8;1488:9;1484:24;1467:51;:::i;:::-;1457:61;;;985:539;;;;;:::o;1721:163::-;1788:20;;1848:10;1837:22;;1827:33;;1817:61;;1874:1;1871;1864:12;1817:61;1721:163;;;:::o;1889:165::-;1956:20;;2016:12;2005:24;;1995:35;;1985:63;;2044:1;2041;2034:12;2059:201;2148:20;;2208:26;2197:38;;2187:49;;2177:77;;2250:1;2247;2240:12;2265:594;2393:6;2401;2409;2417;2425;2433;2486:3;2474:9;2465:7;2461:23;2457:33;2454:53;;;2503:1;2500;2493:12;2454:53;2539:9;2526:23;2516:33;;2568:37;2601:2;2590:9;2586:18;2568:37;:::i;:::-;2558:47;;2624:37;2657:2;2646:9;2642:18;2624:37;:::i;:::-;2614:47;;2680:37;2713:2;2702:9;2698:18;2680:37;:::i;:::-;2670:47;;2736:38;2769:3;2758:9;2754:19;2736:38;:::i;:::-;2726:48;;2793:60;2848:3;2837:9;2833:19;2793:60;:::i;:::-;2783:70;;2265:594;;;;;;;;:::o;2864:605::-;2974:4;3003:2;3032;3021:9;3014:21;3064:6;3058:13;3107:6;3102:2;3091:9;3087:18;3080:34;3132:1;3142:140;3156:6;3153:1;3150:13;3142:140;;;3251:14;;;3247:23;;3241:30;3217:17;;;3236:2;3213:26;3206:66;3171:10;;3142:140;;;3146:3;3331:1;3326:2;3317:6;3306:9;3302:22;3298:31;3291:42;3460:2;3390:66;3385:2;3377:6;3373:15;3369:88;3358:9;3354:104;3350:113;3342:121;;;;2864:605;;;;:::o;3474:320::-;3542:6;3595:2;3583:9;3574:7;3570:23;3566:32;3563:52;;;3611:1;3608;3601:12;3563:52;3651:9;3638:23;3684:18;3676:6;3673:30;3670:50;;;3716:1;3713;3706:12;3670:50;3739:49;3780:7;3771:6;3760:9;3756:22;3739:49;:::i;4872:252::-;4939:6;4947;5000:2;4988:9;4979:7;4975:23;4971:32;4968:52;;;5016:1;5013;5006:12;4968:52;5052:9;5039:23;5029:33;;5081:37;5114:2;5103:9;5099:18;5081:37;:::i;:::-;5071:47;;4872:252;;;;;:::o;5129:452::-;5240:6;5248;5256;5264;5317:3;5305:9;5296:7;5292:23;5288:33;5285:53;;;5334:1;5331;5324:12;5285:53;5357:28;5375:9;5357:28;:::i;:::-;5347:38;;5404:37;5437:2;5426:9;5422:18;5404:37;:::i;:::-;5394:47;;5460:37;5493:2;5482:9;5478:18;5460:37;:::i;:::-;5450:47;;5516:59;5571:2;5560:9;5556:18;5516:59;:::i;:::-;5506:69;;5129:452;;;;;;;:::o;6446:279::-;6511:9;;;6532:10;;;6529:190;;;6575:77;6572:1;6565:88;6676:4;6673:1;6666:15;6704:4;6701:1;6694:15","abiDefinition":[{"inputs":[],"name":"IndexedTooMuch","type":"error"},{"inputs":[],"name":"OccupiedMemory","type":"error"},{"inputs":[],"name":"PrecompileOutOfGas","type":"error"},{"inputs":[],"name":"UnallocatedMemory","type":"error"},{"inputs":[],"name":"UnformattedState","type":"error"},{"inputs":[],"name":"ViewOverrun","type":"error"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"blockNumber","outputs":[{"internalType":"uint40","name":"","type":"uint40"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"castToState","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"a","type":"bytes"},{"internalType":"bytes","name":"b","type":"bytes"}],"name":"equals","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"root_","type":"bytes32"},{"internalType":"uint32","name":"origin_","type":"uint32"},{"internalType":"uint32","name":"nonce_","type":"uint32"},{"internalType":"uint40","name":"blockNumber_","type":"uint40"},{"internalType":"uint40","name":"timestamp_","type":"uint40"},{"internalType":"GasData","name":"gasData_","type":"uint96"}],"name":"formatState","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"gasData","outputs":[{"internalType":"GasData","name":"","type":"uint96"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"hashInvalid","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"isState","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"leaf","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"root_","type":"bytes32"},{"internalType":"uint32","name":"origin_","type":"uint32"}],"name":"leftLeaf","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"nonce","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"origin","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint32","name":"nonce_","type":"uint32"},{"internalType":"uint40","name":"blockNumber_","type":"uint40"},{"internalType":"uint40","name":"timestamp_","type":"uint40"},{"internalType":"GasData","name":"gasData_","type":"uint96"}],"name":"rightLeaf","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"subLeafs","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"timestamp","outputs":[{"internalType":"uint40","name":"","type":"uint40"}],"stateMutability":"pure","type":"function"}],"userDoc":{"kind":"user","methods":{},"notice":"Exposes State methods for testing against golang.","version":1},"developerDoc":{"kind":"dev","methods":{},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"IndexedTooMuch\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"OccupiedMemory\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"PrecompileOutOfGas\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"UnallocatedMemory\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"UnformattedState\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"ViewOverrun\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"blockNumber\",\"outputs\":[{\"internalType\":\"uint40\",\"name\":\"\",\"type\":\"uint40\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"castToState\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"a\",\"type\":\"bytes\"},{\"internalType\":\"bytes\",\"name\":\"b\",\"type\":\"bytes\"}],\"name\":\"equals\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"root_\",\"type\":\"bytes32\"},{\"internalType\":\"uint32\",\"name\":\"origin_\",\"type\":\"uint32\"},{\"internalType\":\"uint32\",\"name\":\"nonce_\",\"type\":\"uint32\"},{\"internalType\":\"uint40\",\"name\":\"blockNumber_\",\"type\":\"uint40\"},{\"internalType\":\"uint40\",\"name\":\"timestamp_\",\"type\":\"uint40\"},{\"internalType\":\"GasData\",\"name\":\"gasData_\",\"type\":\"uint96\"}],\"name\":\"formatState\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"gasData\",\"outputs\":[{\"internalType\":\"GasData\",\"name\":\"\",\"type\":\"uint96\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"hashInvalid\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"isState\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"leaf\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"root_\",\"type\":\"bytes32\"},{\"internalType\":\"uint32\",\"name\":\"origin_\",\"type\":\"uint32\"}],\"name\":\"leftLeaf\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"nonce\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"origin\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"\",\"type\":\"uint32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32\",\"name\":\"nonce_\",\"type\":\"uint32\"},{\"internalType\":\"uint40\",\"name\":\"blockNumber_\",\"type\":\"uint40\"},{\"internalType\":\"uint40\",\"name\":\"timestamp_\",\"type\":\"uint40\"},{\"internalType\":\"GasData\",\"name\":\"gasData_\",\"type\":\"uint96\"}],\"name\":\"rightLeaf\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"root\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"subLeafs\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"payload\",\"type\":\"bytes\"}],\"name\":\"timestamp\",\"outputs\":[{\"internalType\":\"uint40\",\"name\":\"\",\"type\":\"uint40\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"notice\":\"Exposes State methods for testing against golang.\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/StateHarness.t.sol\":\"StateHarness\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/StateHarness.t.sol\":{\"keccak256\":\"0x18cffce3039e8ab774b0011a4bbf9812533e064bdfebfe70b931ec2427614089\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://d1081451a985d6522077ce9dd2bf81a2d3f726e1003a3b588240ed416968ee36\",\"dweb:/ipfs/QmPmWLB1F2KzmCwmr1KTwFbPtHnE11Axr386vjrBc4aWM9\"]}},\"version\":1}"},"hashes":{"blockNumber(bytes)":"e948e600","castToState(bytes)":"5fed0261","equals(bytes,bytes)":"137e618a","formatState(bytes32,uint32,uint32,uint40,uint40,uint96)":"17ebb0b7","gasData(bytes)":"5a0ca172","hashInvalid(bytes)":"60cf3bf0","isState(bytes)":"aae6d884","leaf(bytes)":"d7a7a72c","leftLeaf(bytes32,uint32)":"edaa471d","nonce(bytes)":"4e765004","origin(bytes)":"cb3eb0e1","rightLeaf(uint32,uint40,uint40,uint96)":"f8cb7943","root(bytes)":"c2e9e208","subLeafs(bytes)":"9aaa1826","timestamp(bytes)":"1c9aa222"}},"solidity/StateHarness.t.sol:StateLib":{"code":"0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212203eb6d07d2647fe44fc88231538b70b6d231d369d9c9d3811327aef5bda5c22b464736f6c63430008110033","runtime-code":"0x73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212203eb6d07d2647fe44fc88231538b70b6d231d369d9c9d3811327aef5bda5c22b464736f6c63430008110033","info":{"source":"// SPDX-License-Identifier: MIT\npragma solidity =0.8.17;\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// contracts/libs/memory/MemView.sol\n\n/// @dev MemView is an untyped view over a portion of memory to be used instead of `bytes memory`\ntype MemView is uint256;\n\n/// @dev Attach library functions to MemView\nusing MemViewLib for MemView global;\n\n/// @notice Library for operations with the memory views.\n/// Forked from https://github.com/summa-tx/memview-sol with several breaking changes:\n/// - The codebase is ported to Solidity 0.8\n/// - Custom errors are added\n/// - The runtime type checking is replaced with compile-time check provided by User-Defined Value Types\n/// https://docs.soliditylang.org/en/latest/types.html#user-defined-value-types\n/// - uint256 is used as the underlying type for the \"memory view\" instead of bytes29.\n/// It is wrapped into MemView custom type in order not to be confused with actual integers.\n/// - Therefore the \"type\" field is discarded, allowing to allocate 16 bytes for both view location and length\n/// - The documentation is expanded\n/// - Library functions unused by the rest of the codebase are removed\n// - Very pretty code separators are added :)\nlibrary MemViewLib {\n /// @notice Stack layout for uint256 (from highest bits to lowest)\n /// (32 .. 16] loc 16 bytes Memory address of underlying bytes\n /// (16 .. 00] len 16 bytes Length of underlying bytes\n\n // ═══════════════════════════════════════════ BUILDING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Instantiate a new untyped memory view. This should generally not be called directly.\n * Prefer `ref` wherever possible.\n * @param loc_ The memory address\n * @param len_ The length\n * @return The new view with the specified location and length\n */\n function build(uint256 loc_, uint256 len_) internal pure returns (MemView) {\n uint256 end_ = loc_ + len_;\n // Make sure that a view is not constructed that points to unallocated memory\n // as this could be indicative of a buffer overflow attack\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n if gt(end_, mload(0x40)) { end_ := 0 }\n }\n if (end_ == 0) {\n revert UnallocatedMemory();\n }\n return _unsafeBuildUnchecked(loc_, len_);\n }\n\n /**\n * @notice Instantiate a memory view from a byte array.\n * @dev Note that due to Solidity memory representation, it is not possible to\n * implement a deref, as the `bytes` type stores its len in memory.\n * @param arr The byte array\n * @return The memory view over the provided byte array\n */\n function ref(bytes memory arr) internal pure returns (MemView) {\n uint256 len_ = arr.length;\n // `bytes arr` is stored in memory in the following way\n // 1. First, uint256 arr.length is stored. That requires 32 bytes (0x20).\n // 2. Then, the array data is stored.\n uint256 loc_;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // We add 0x20, so that the view starts exactly where the array data starts\n loc_ := add(arr, 0x20)\n }\n return build(loc_, len_);\n }\n\n // ════════════════════════════════════════════ CLONING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Copies the referenced memory to a new loc in memory, returning a `bytes` pointing to the new memory.\n * @param memView The memory view\n * @return arr The cloned byte array\n */\n function clone(MemView memView) internal view returns (bytes memory arr) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n // This is where the byte array will be stored\n arr := ptr\n }\n unchecked {\n _unsafeCopyTo(memView, ptr + 0x20);\n }\n // `bytes arr` is stored in memory in the following way\n // 1. First, uint256 arr.length is stored. That requires 32 bytes (0x20).\n // 2. Then, the array data is stored.\n uint256 len_ = memView.len();\n uint256 footprint_ = memView.footprint();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Write new unused pointer: the old value + array footprint + 32 bytes to store the length\n mstore(0x40, add(add(ptr, footprint_), 0x20))\n // Write len of new array (in bytes)\n mstore(ptr, len_)\n }\n }\n\n /**\n * @notice Copies all views, joins them into a new bytearray.\n * @param memViews The memory views\n * @return arr The new byte array with joined data behind the given views\n */\n function join(MemView[] memory memViews) internal view returns (bytes memory arr) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n // This is where the byte array will be stored\n arr := ptr\n }\n MemView newView;\n unchecked {\n newView = _unsafeJoin(memViews, ptr + 0x20);\n }\n uint256 len_ = newView.len();\n uint256 footprint_ = newView.footprint();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Write new unused pointer: the old value + array footprint + 32 bytes to store the length\n mstore(0x40, add(add(ptr, footprint_), 0x20))\n // Write len of new array (in bytes)\n mstore(ptr, len_)\n }\n }\n\n // ══════════════════════════════════════════ INSPECTING MEMORY VIEW ═══════════════════════════════════════════════\n\n /**\n * @notice Returns the memory address of the underlying bytes.\n * @param memView The memory view\n * @return loc_ The memory address\n */\n function loc(MemView memView) internal pure returns (uint256 loc_) {\n // loc is stored in the highest 16 bytes of the underlying uint256\n return MemView.unwrap(memView) \u003e\u003e 128;\n }\n\n /**\n * @notice Returns the number of bytes of the view.\n * @param memView The memory view\n * @return len_ The length of the view\n */\n function len(MemView memView) internal pure returns (uint256 len_) {\n // len is stored in the lowest 16 bytes of the underlying uint256\n return MemView.unwrap(memView) \u0026 type(uint128).max;\n }\n\n /**\n * @notice Returns the endpoint of `memView`.\n * @param memView The memory view\n * @return end_ The endpoint of `memView`\n */\n function end(MemView memView) internal pure returns (uint256 end_) {\n // The endpoint never overflows uint128, let alone uint256, so we could use unchecked math here\n unchecked {\n return memView.loc() + memView.len();\n }\n }\n\n /**\n * @notice Returns the number of memory words this memory view occupies, rounded up.\n * @param memView The memory view\n * @return words_ The number of memory words\n */\n function words(MemView memView) internal pure returns (uint256 words_) {\n // returning ceil(length / 32.0)\n unchecked {\n return (memView.len() + 31) \u003e\u003e 5;\n }\n }\n\n /**\n * @notice Returns the in-memory footprint of a fresh copy of the view.\n * @param memView The memory view\n * @return footprint_ The in-memory footprint of a fresh copy of the view.\n */\n function footprint(MemView memView) internal pure returns (uint256 footprint_) {\n // words() * 32\n return memView.words() \u003c\u003c 5;\n }\n\n // ════════════════════════════════════════════ HASHING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Returns the keccak256 hash of the underlying memory\n * @param memView The memory view\n * @return digest The keccak256 hash of the underlying memory\n */\n function keccak(MemView memView) internal pure returns (bytes32 digest) {\n uint256 loc_ = memView.loc();\n uint256 len_ = memView.len();\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n digest := keccak256(loc_, len_)\n }\n }\n\n /**\n * @notice Adds a salt to the keccak256 hash of the underlying data and returns the keccak256 hash of the\n * resulting data.\n * @param memView The memory view\n * @return digestSalted keccak256(salt, keccak256(memView))\n */\n function keccakSalted(MemView memView, bytes32 salt) internal pure returns (bytes32 digestSalted) {\n return keccak256(bytes.concat(salt, memView.keccak()));\n }\n\n // ════════════════════════════════════════════ SLICING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Safe slicing without memory modification.\n * @param memView The memory view\n * @param index_ The start index\n * @param len_ The length\n * @return The new view for the slice of the given length starting from the given index\n */\n function slice(MemView memView, uint256 index_, uint256 len_) internal pure returns (MemView) {\n uint256 loc_ = memView.loc();\n // Ensure it doesn't overrun the view\n if (loc_ + index_ + len_ \u003e memView.end()) {\n revert ViewOverrun();\n }\n // Build a view starting from index with the given length\n unchecked {\n // loc_ + index_ \u003c= memView.end()\n return build({loc_: loc_ + index_, len_: len_});\n }\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing bytes from `index` to end(memView).\n * @param memView The memory view\n * @param index_ The start index\n * @return The new view for the slice starting from the given index until the initial view endpoint\n */\n function sliceFrom(MemView memView, uint256 index_) internal pure returns (MemView) {\n uint256 len_ = memView.len();\n // Ensure it doesn't overrun the view\n if (index_ \u003e len_) {\n revert ViewOverrun();\n }\n // Build a view starting from index with the given length\n unchecked {\n // index_ \u003c= len_ =\u003e memView.loc() + index_ \u003c= memView.loc() + memView.len() == memView.end()\n return build({loc_: memView.loc() + index_, len_: len_ - index_});\n }\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing the first `len` bytes.\n * @param memView The memory view\n * @param len_ The length\n * @return The new view for the slice of the given length starting from the initial view beginning\n */\n function prefix(MemView memView, uint256 len_) internal pure returns (MemView) {\n return memView.slice({index_: 0, len_: len_});\n }\n\n /**\n * @notice Shortcut to `slice`. Gets a view representing the last `len` byte.\n * @param memView The memory view\n * @param len_ The length\n * @return The new view for the slice of the given length until the initial view endpoint\n */\n function postfix(MemView memView, uint256 len_) internal pure returns (MemView) {\n uint256 viewLen = memView.len();\n // Ensure it doesn't overrun the view\n if (len_ \u003e viewLen) {\n revert ViewOverrun();\n }\n // Could do the unchecked math due to the check above\n uint256 index_;\n unchecked {\n index_ = viewLen - len_;\n }\n // Build a view starting from index with the given length\n unchecked {\n // len_ \u003c= memView.len() =\u003e memView.loc() \u003c= loc_ \u003c= memView.end()\n return build({loc_: memView.loc() + viewLen - len_, len_: len_});\n }\n }\n\n // ═══════════════════════════════════════════ INDEXING MEMORY VIEW ════════════════════════════════════════════════\n\n /**\n * @notice Load up to 32 bytes from the view onto the stack.\n * @dev Returns a bytes32 with only the `bytes_` HIGHEST bytes set.\n * This can be immediately cast to a smaller fixed-length byte array.\n * To automatically cast to an integer, use `indexUint`.\n * @param memView The memory view\n * @param index_ The index\n * @param bytes_ The amount of bytes to load onto the stack\n * @return result The 32 byte result having only `bytes_` highest bytes set\n */\n function index(MemView memView, uint256 index_, uint256 bytes_) internal pure returns (bytes32 result) {\n if (bytes_ == 0) {\n return bytes32(0);\n }\n // Can't load more than 32 bytes to the stack in one go\n if (bytes_ \u003e 32) {\n revert IndexedTooMuch();\n }\n // The last indexed byte should be within view boundaries\n if (index_ + bytes_ \u003e memView.len()) {\n revert ViewOverrun();\n }\n uint256 bitLength = bytes_ \u003c\u003c 3; // bytes_ * 8\n uint256 loc_ = memView.loc();\n // Get a mask with `bitLength` highest bits set\n uint256 mask;\n // 0x800...00 binary representation is 100...00\n // sar stands for \"signed arithmetic shift\": https://en.wikipedia.org/wiki/Arithmetic_shift\n // sar(N-1, 100...00) = 11...100..00, with exactly N highest bits set to 1\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n mask := sar(sub(bitLength, 1), 0x8000000000000000000000000000000000000000000000000000000000000000)\n }\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load a full word using index offset, and apply mask to ignore non-relevant bytes\n result := and(mload(add(loc_, index_)), mask)\n }\n }\n\n /**\n * @notice Parse an unsigned integer from the view at `index`.\n * @dev Requires that the view have \u003e= `bytes_` bytes following that index.\n * @param memView The memory view\n * @param index_ The index\n * @param bytes_ The amount of bytes to load onto the stack\n * @return The unsigned integer\n */\n function indexUint(MemView memView, uint256 index_, uint256 bytes_) internal pure returns (uint256) {\n bytes32 indexedBytes = memView.index(index_, bytes_);\n // `index()` returns left-aligned `bytes_`, while integers are right-aligned\n // Shifting here to right-align with the full 32 bytes word: need to shift right `(32 - bytes_)` bytes\n unchecked {\n // memView.index() reverts when bytes_ \u003e 32, thus unchecked math\n return uint256(indexedBytes) \u003e\u003e ((32 - bytes_) \u003c\u003c 3);\n }\n }\n\n /**\n * @notice Parse an address from the view at `index`.\n * @dev Requires that the view have \u003e= 20 bytes following that index.\n * @param memView The memory view\n * @param index_ The index\n * @return The address\n */\n function indexAddress(MemView memView, uint256 index_) internal pure returns (address) {\n // index 20 bytes as `uint160`, and then cast to `address`\n return address(uint160(memView.indexUint(index_, 20)));\n }\n\n // ══════════════════════════════════════════════ PRIVATE HELPERS ══════════════════════════════════════════════════\n\n /// @dev Returns a memory view over the specified memory location\n /// without checking if it points to unallocated memory.\n function _unsafeBuildUnchecked(uint256 loc_, uint256 len_) private pure returns (MemView) {\n // There is no scenario where loc or len would overflow uint128, so we omit this check.\n // We use the highest 128 bits to encode the location and the lowest 128 bits to encode the length.\n return MemView.wrap((loc_ \u003c\u003c 128) | len_);\n }\n\n /**\n * @notice Copy the view to a location, return an unsafe memory reference\n * @dev Super Dangerous direct memory access.\n * This reference can be overwritten if anything else modifies memory (!!!).\n * As such it MUST be consumed IMMEDIATELY. Update the free memory pointer to ensure the copied data\n * is not overwritten. This function is private to prevent unsafe usage by callers.\n * @param memView The memory view\n * @param newLoc The new location to copy the underlying view data\n * @return The memory view over the unsafe memory with the copied underlying data\n */\n function _unsafeCopyTo(MemView memView, uint256 newLoc) private view returns (MemView) {\n uint256 len_ = memView.len();\n uint256 oldLoc = memView.loc();\n\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n }\n // Revert if we're writing in occupied memory\n if (newLoc \u003c ptr) {\n revert OccupiedMemory();\n }\n bool res;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // use the identity precompile (0x04) to copy\n res := staticcall(gas(), 0x04, oldLoc, len_, newLoc, len_)\n }\n if (!res) revert PrecompileOutOfGas();\n return _unsafeBuildUnchecked({loc_: newLoc, len_: len_});\n }\n\n /**\n * @notice Join the views in memory, return an unsafe reference to the memory.\n * @dev Super Dangerous direct memory access.\n * This reference can be overwritten if anything else modifies memory (!!!).\n * As such it MUST be consumed IMMEDIATELY. Update the free memory pointer to ensure the copied data\n * is not overwritten. This function is private to prevent unsafe usage by callers.\n * @param memViews The memory views\n * @return The conjoined view pointing to the new memory\n */\n function _unsafeJoin(MemView[] memory memViews, uint256 location) private view returns (MemView) {\n uint256 ptr;\n assembly {\n // solhint-disable-previous-line no-inline-assembly\n // Load unused memory pointer\n ptr := mload(0x40)\n }\n // Revert if we're writing in occupied memory\n if (location \u003c ptr) {\n revert OccupiedMemory();\n }\n // Copy the views to the specified location one by one, by tracking the amount of copied bytes so far\n uint256 offset = 0;\n for (uint256 i = 0; i \u003c memViews.length;) {\n MemView memView = memViews[i];\n // We can use the unchecked math here as location + sum(view.length) will never overflow uint256\n unchecked {\n _unsafeCopyTo(memView, location + offset);\n offset += memView.len();\n ++i;\n }\n }\n return _unsafeBuildUnchecked({loc_: location, len_: offset});\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// contracts/libs/memory/State.sol\n\n/// State is a memory view over a formatted state payload.\ntype State is uint256;\n\nusing StateLib for State global;\n\n/// # State\n/// State structure represents the state of Origin contract at some point of time.\n/// - State is structured in a way to track the updates of the Origin Merkle Tree.\n/// - State includes root of the Origin Merkle Tree, origin domain and some additional metadata.\n/// ## Origin Merkle Tree\n/// Hash of every sent message is inserted in the Origin Merkle Tree, which changes\n/// the value of Origin Merkle Root (which is the root for the mentioned tree).\n/// - Origin has a single Merkle Tree for all messages, regardless of their destination domain.\n/// - This leads to Origin state being updated if and only if a message was sent in a block.\n/// - Origin contract is a \"source of truth\" for states: a state is considered \"valid\" in its Origin,\n/// if it matches the state of the Origin contract after the N-th (nonce) message was sent.\n///\n/// # Memory layout of State fields\n///\n/// | Position | Field | Type | Bytes | Description |\n/// | ---------- | ----------- | ------- | ----- | ------------------------------ |\n/// | [000..032) | root | bytes32 | 32 | Root of the Origin Merkle Tree |\n/// | [032..036) | origin | uint32 | 4 | Domain where Origin is located |\n/// | [036..040) | nonce | uint32 | 4 | Amount of sent messages |\n/// | [040..045) | blockNumber | uint40 | 5 | Block of last sent message |\n/// | [045..050) | timestamp | uint40 | 5 | Time of last sent message |\n/// | [050..062) | gasData | uint96 | 12 | Gas data for the chain |\n///\n/// @dev State could be used to form a Snapshot to be signed by a Guard or a Notary.\nlibrary StateLib {\n using MemViewLib for bytes;\n\n /// @dev The variables below are not supposed to be used outside of the library directly.\n uint256 private constant OFFSET_ROOT = 0;\n uint256 private constant OFFSET_ORIGIN = 32;\n uint256 private constant OFFSET_NONCE = 36;\n uint256 private constant OFFSET_BLOCK_NUMBER = 40;\n uint256 private constant OFFSET_TIMESTAMP = 45;\n uint256 private constant OFFSET_GAS_DATA = 50;\n\n // ═══════════════════════════════════════════════════ STATE ═══════════════════════════════════════════════════════\n\n /**\n * @notice Returns a formatted State payload with provided fields\n * @param root_ New merkle root\n * @param origin_ Domain of Origin's chain\n * @param nonce_ Nonce of the merkle root\n * @param blockNumber_ Block number when root was saved in Origin\n * @param timestamp_ Block timestamp when root was saved in Origin\n * @param gasData_ Gas data for the chain\n * @return Formatted state\n */\n function formatState(\n bytes32 root_,\n uint32 origin_,\n uint32 nonce_,\n uint40 blockNumber_,\n uint40 timestamp_,\n GasData gasData_\n ) internal pure returns (bytes memory) {\n return abi.encodePacked(root_, origin_, nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n /**\n * @notice Returns a State view over the given payload.\n * @dev Will revert if the payload is not a state.\n */\n function castToState(bytes memory payload) internal pure returns (State) {\n return castToState(payload.ref());\n }\n\n /**\n * @notice Casts a memory view to a State view.\n * @dev Will revert if the memory view is not over a state.\n */\n function castToState(MemView memView) internal pure returns (State) {\n if (!isState(memView)) revert UnformattedState();\n return State.wrap(MemView.unwrap(memView));\n }\n\n /// @notice Checks that a payload is a formatted State.\n function isState(MemView memView) internal pure returns (bool) {\n return memView.len() == STATE_LENGTH;\n }\n\n /// @notice Returns the hash of a State, that could be later signed by a Guard to signal\n /// that the state is invalid.\n function hashInvalid(State state) internal pure returns (bytes32) {\n // The final hash to sign is keccak(stateInvalidSalt, keccak(state))\n return state.unwrap().keccakSalted(STATE_INVALID_SALT);\n }\n\n /// @notice Convenience shortcut for unwrapping a view.\n function unwrap(State state) internal pure returns (MemView) {\n return MemView.wrap(State.unwrap(state));\n }\n\n /// @notice Compares two State structures.\n function equals(State a, State b) internal pure returns (bool) {\n // Length of a State payload is fixed, so we just need to compare the hashes\n return a.unwrap().keccak() == b.unwrap().keccak();\n }\n\n // ═══════════════════════════════════════════════ STATE HASHING ═══════════════════════════════════════════════════\n\n /// @notice Returns the hash of the State.\n /// @dev We are using the Merkle Root of a tree with two leafs (see below) as state hash.\n function leaf(State state) internal pure returns (bytes32) {\n (bytes32 leftLeaf_, bytes32 rightLeaf_) = state.subLeafs();\n // Final hash is the parent of these leafs\n return keccak256(bytes.concat(leftLeaf_, rightLeaf_));\n }\n\n /// @notice Returns \"sub-leafs\" of the State. Hash of these \"sub leafs\" is going to be used\n /// as a \"state leaf\" in the \"Snapshot Merkle Tree\".\n /// This enables proving that leftLeaf = (root, origin) was a part of the \"Snapshot Merkle Tree\",\n /// by combining `rightLeaf` with the remainder of the \"Snapshot Merkle Proof\".\n function subLeafs(State state) internal pure returns (bytes32 leftLeaf_, bytes32 rightLeaf_) {\n MemView memView = state.unwrap();\n // Left leaf is (root, origin)\n leftLeaf_ = memView.prefix({len_: OFFSET_NONCE}).keccak();\n // Right leaf is (metadata), or (nonce, blockNumber, timestamp)\n rightLeaf_ = memView.sliceFrom({index_: OFFSET_NONCE}).keccak();\n }\n\n /// @notice Returns the left \"sub-leaf\" of the State.\n function leftLeaf(bytes32 root_, uint32 origin_) internal pure returns (bytes32) {\n // We use encodePacked here to simulate the State memory layout\n return keccak256(abi.encodePacked(root_, origin_));\n }\n\n /// @notice Returns the right \"sub-leaf\" of the State.\n function rightLeaf(uint32 nonce_, uint40 blockNumber_, uint40 timestamp_, GasData gasData_)\n internal\n pure\n returns (bytes32)\n {\n // We use encodePacked here to simulate the State memory layout\n return keccak256(abi.encodePacked(nonce_, blockNumber_, timestamp_, gasData_));\n }\n\n // ═══════════════════════════════════════════════ STATE SLICING ═══════════════════════════════════════════════════\n\n /// @notice Returns a historical Merkle root from the Origin contract.\n function root(State state) internal pure returns (bytes32) {\n return state.unwrap().index({index_: OFFSET_ROOT, bytes_: 32});\n }\n\n /// @notice Returns domain of chain where the Origin contract is deployed.\n function origin(State state) internal pure returns (uint32) {\n // Can be safely casted to uint32, since we index 4 bytes\n return uint32(state.unwrap().indexUint({index_: OFFSET_ORIGIN, bytes_: 4}));\n }\n\n /// @notice Returns nonce of Origin contract at the time, when `root` was the Merkle root.\n function nonce(State state) internal pure returns (uint32) {\n // Can be safely casted to uint32, since we index 4 bytes\n return uint32(state.unwrap().indexUint({index_: OFFSET_NONCE, bytes_: 4}));\n }\n\n /// @notice Returns a block number when `root` was saved in Origin.\n function blockNumber(State state) internal pure returns (uint40) {\n // Can be safely casted to uint40, since we index 5 bytes\n return uint40(state.unwrap().indexUint({index_: OFFSET_BLOCK_NUMBER, bytes_: 5}));\n }\n\n /// @notice Returns a block timestamp when `root` was saved in Origin.\n /// @dev This is the timestamp according to the origin chain.\n function timestamp(State state) internal pure returns (uint40) {\n // Can be safely casted to uint40, since we index 5 bytes\n return uint40(state.unwrap().indexUint({index_: OFFSET_TIMESTAMP, bytes_: 5}));\n }\n\n /// @notice Returns gas data for the chain.\n function gasData(State state) internal pure returns (GasData) {\n return GasDataLib.wrapGasData(state.unwrap().indexUint({index_: OFFSET_GAS_DATA, bytes_: GAS_DATA_LENGTH}));\n }\n}\n\n// test/harnesses/libs/memory/StateHarness.t.sol\n\n// solhint-disable ordering\n/// @notice Exposes State methods for testing against golang.\ncontract StateHarness {\n using StateLib for bytes;\n using StateLib for MemView;\n using MemViewLib for bytes;\n\n // Note: we don't add an empty test() function here, as it currently leads\n // to zero coverage on the corresponding library.\n\n // ══════════════════════════════════════════════════ GETTERS ══════════════════════════════════════════════════════\n\n function castToState(bytes memory payload) public view returns (bytes memory) {\n // Walkaround to get the forge coverage working on libraries, see\n // https://github.com/foundry-rs/foundry/pull/3128#issuecomment-1241245086\n State state = StateLib.castToState(payload);\n return state.unwrap().clone();\n }\n\n function equals(bytes memory a, bytes memory b) public pure returns (bool) {\n return a.castToState().equals(b.castToState());\n }\n\n function hashInvalid(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().hashInvalid();\n }\n\n function leaf(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().leaf();\n }\n\n function subLeafs(bytes memory payload) public pure returns (bytes32, bytes32) {\n return payload.castToState().subLeafs();\n }\n\n function leftLeaf(bytes32 root_, uint32 origin_) public pure returns (bytes32) {\n return StateLib.leftLeaf(root_, origin_);\n }\n\n function rightLeaf(uint32 nonce_, uint40 blockNumber_, uint40 timestamp_, GasData gasData_)\n public\n pure\n returns (bytes32)\n {\n return StateLib.rightLeaf(nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n function root(bytes memory payload) public pure returns (bytes32) {\n return payload.castToState().root();\n }\n\n function origin(bytes memory payload) public pure returns (uint32) {\n return payload.castToState().origin();\n }\n\n function nonce(bytes memory payload) public pure returns (uint32) {\n return payload.castToState().nonce();\n }\n\n function blockNumber(bytes memory payload) public pure returns (uint40) {\n return payload.castToState().blockNumber();\n }\n\n function timestamp(bytes memory payload) public pure returns (uint40) {\n return payload.castToState().timestamp();\n }\n\n function gasData(bytes memory payload) public pure returns (GasData) {\n return payload.castToState().gasData();\n }\n\n // ════════════════════════════════════════════════ FORMATTERS ═════════════════════════════════════════════════════\n\n function formatState(\n bytes32 root_,\n uint32 origin_,\n uint32 nonce_,\n uint40 blockNumber_,\n uint40 timestamp_,\n GasData gasData_\n ) public pure returns (bytes memory) {\n return StateLib.formatState(root_, origin_, nonce_, blockNumber_, timestamp_, gasData_);\n }\n\n function isState(bytes memory payload) public pure returns (bool) {\n return payload.ref().isState();\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":"46401:7325:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;46401:7325:0;;;;;;;;;;;;;;;;;","srcMapRuntime":"46401:7325:0:-:0;;;;;;;;","abiDefinition":[],"userDoc":{"kind":"user","methods":{},"notice":"# State State structure represents the state of Origin contract at some point of time. - State is structured in a way to track the updates of the Origin Merkle Tree. - State includes root of the Origin Merkle Tree, origin domain and some additional metadata. ## Origin Merkle Tree Hash of every sent message is inserted in the Origin Merkle Tree, which changes the value of Origin Merkle Root (which is the root for the mentioned tree). - Origin has a single Merkle Tree for all messages, regardless of their destination domain. - This leads to Origin state being updated if and only if a message was sent in a block. - Origin contract is a \"source of truth\" for states: a state is considered \"valid\" in its Origin, if it matches the state of the Origin contract after the N-th (nonce) message was sent. # Memory layout of State fields | Position | Field | Type | Bytes | Description | | ---------- | ----------- | ------- | ----- | ------------------------------ | | [000..032) | root | bytes32 | 32 | Root of the Origin Merkle Tree | | [032..036) | origin | uint32 | 4 | Domain where Origin is located | | [036..040) | nonce | uint32 | 4 | Amount of sent messages | | [040..045) | blockNumber | uint40 | 5 | Block of last sent message | | [045..050) | timestamp | uint40 | 5 | Time of last sent message | | [050..062) | gasData | uint96 | 12 | Gas data for the chain |","version":1},"developerDoc":{"details":"State could be used to form a Snapshot to be signed by a Guard or a Notary.","kind":"dev","methods":{},"stateVariables":{"OFFSET_ROOT":{"details":"The variables below are not supposed to be used outside of the library directly."}},"version":1},"metadata":"{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"details\":\"State could be used to form a Snapshot to be signed by a Guard or a Notary.\",\"kind\":\"dev\",\"methods\":{},\"stateVariables\":{\"OFFSET_ROOT\":{\"details\":\"The variables below are not supposed to be used outside of the library directly.\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"notice\":\"# State State structure represents the state of Origin contract at some point of time. - State is structured in a way to track the updates of the Origin Merkle Tree. - State includes root of the Origin Merkle Tree, origin domain and some additional metadata. ## Origin Merkle Tree Hash of every sent message is inserted in the Origin Merkle Tree, which changes the value of Origin Merkle Root (which is the root for the mentioned tree). - Origin has a single Merkle Tree for all messages, regardless of their destination domain. - This leads to Origin state being updated if and only if a message was sent in a block. - Origin contract is a \\\"source of truth\\\" for states: a state is considered \\\"valid\\\" in its Origin, if it matches the state of the Origin contract after the N-th (nonce) message was sent. # Memory layout of State fields | Position | Field | Type | Bytes | Description | | ---------- | ----------- | ------- | ----- | ------------------------------ | | [000..032) | root | bytes32 | 32 | Root of the Origin Merkle Tree | | [032..036) | origin | uint32 | 4 | Domain where Origin is located | | [036..040) | nonce | uint32 | 4 | Amount of sent messages | | [040..045) | blockNumber | uint40 | 5 | Block of last sent message | | [045..050) | timestamp | uint40 | 5 | Time of last sent message | | [050..062) | gasData | uint96 | 12 | Gas data for the chain |\",\"version\":1}},\"settings\":{\"compilationTarget\":{\"solidity/StateHarness.t.sol\":\"StateLib\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"solidity/StateHarness.t.sol\":{\"keccak256\":\"0x18cffce3039e8ab774b0011a4bbf9812533e064bdfebfe70b931ec2427614089\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://d1081451a985d6522077ce9dd2bf81a2d3f726e1003a3b588240ed416968ee36\",\"dweb:/ipfs/QmPmWLB1F2KzmCwmr1KTwFbPtHnE11Axr386vjrBc4aWM9\"]}},\"version\":1}"},"hashes":{}}}