Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- MessageBridge
- Optimization enabled
- false
- Compiler version
- v0.8.28+commit.7893614a
- EVM Version
- Verified at
- 2026-11-21T15:05:05.878897Z
Constructor Arguments
0000000000000000000000001dbbcc0bc25de5f6ae122fb0009b3ee4931fd9580000000000000000000000000000000000000000000000000000000000aa36a7000000000000000000000000071da4d1b038787c16dae145a8b8c1edb2470f51000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064ddc23ff43ea0cd2ce9a13ef6681ee651e76e4e00000000000000000000000000000000000000000000000000000000000000de00000000000000000000000085fbe4c5f7992fbd97a8e4dafc821fad3b0d20f3
src/hardened/MessageBridge.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {IDepositGate} from "./IDepositGate.sol";
import {BeaconBlockHeader} from "./SSZ.sol";
import {BeaconProofVerifier} from "./BeaconProofVerifier.sol";
import {ReceiptProofLib} from "./ReceiptProofLib.sol";
import {AmbMessageCodec} from "./AmbMessageCodec.sol";
import {IAMB} from "./IAMB.sol";
/// @title MessageBridge
/// @notice One end of a two-chain message bridge with the interface of the OmniBridge Arbitrary Message Bridge. A
/// contract sends a message with `requireToPassMessage`. Anyone proves the message on the other chain with
/// `executeMessage`, and the bridge calls the target. The light client and the proof replace the validators of
/// OmniBridge. The bridge has no owner, no executor fee, no refund and no upgrade path.
/// @dev Sending. `requireToPassMessage` and `requireToConfirmMessage` emit `UserRequestForAffirmation` with the message
/// encoding of `AmbMessageCodec`, which is the OmniBridge encoding unchanged. There is no manual lane, so both calls
/// differ only in the data type byte of the message. A send first needs the deposit lock open, then the fork gate
/// admits it (with empty evidence: a keeper confirms the epoch with `BeaconForkGate.confirm`).
///
/// Delivery. `executeMessage` checks a proof of the log, in this order: the anchor, the ancestry, the block hash, the
/// execution header, the receipt (which must record success), the transaction at the same index, the log (emitter and
/// topic) and the message (identifier, version, chains and data type). A message executes once, and only a call
/// that succeeds counts: when the call to the target fails, `executeMessage` reverts with the error of the target, and
/// the message stays `NotDelivered`, so anyone can deliver it again later, with more gas or after the target changed
/// its mind. Messages are independent: the nonce of the sender only makes identifiers unique, and no order exists
/// between messages.
///
/// Gas. A message carries no gas number that the bridge reads. The target gets all the gas that is left (the EVM
/// keeps back one 64th), and if that is not enough the call fails and the delivery reverts. So an executor that gives
/// too little gas loses only its own transaction: it cannot make a message fail for good. The gas field of the
/// OmniBridge encoding stays in the message, always zero, so the encoding keeps its layout. A target that needs a
/// guarantee for a call of its own (a callback, a follow-up call) states the gas of that call in its own data and
/// checks it itself: the bridge knows nothing about the target.
///
/// The context (`messageSender`, `messageId`, `messageSourceChainId`, `transactionHash`) is set during the call to the
/// target and cleared after it. A target trusts a message by checking `msg.sender == bridge` and the pair
/// (`messageSourceChainId()`, `messageSender()`). While a message executes, another `executeMessage` is refused,
/// because it would overwrite the context. A target may send messages meanwhile: sends do not touch the context.
contract MessageBridge is BeaconProofVerifier, IAMB {
/// @notice The terms at deployment: the cutoff and the remote light client.
/// @param cutoffTimestamp Sends revert from this timestamp on. Zero means no cutoff.
/// @param remoteLightClient The light client on the other chain, which tracks the beacon chain of THIS chain and
/// feeds the remote bridge. `openDeposits` reads its storage. It must not be zero.
/// @dev No fork slot is a term: each proof carries the fork proof of its source state (`MessageProof.sourceFork`).
struct BridgeTerms {
uint64 cutoffTimestamp;
address remoteLightClient;
}
/// @notice The evidence for one message. Nothing in it is secret.
/// @param anchorHeader A stored finalized header. Its root must equal `lightClient.headers(slot)`.
/// @param sourceHeader The beacon block that carries the execution block of the sending transaction.
/// @param ancestryBranch The branch from the root of `sourceHeader` to the state root of `anchorHeader`.
/// @param blockHashBranch The branch from the execution block hash to the body root of `sourceHeader`.
/// @param sourceFork The fork proof of the state of `sourceHeader` (under `sourceHeader.stateRoot`). Its proven shape
/// picks the block hash rule: plain takes the payload layout, progressive (Gloas on) takes the bid parent hash.
/// @param executionHeaderRlp The RLP of the execution block header. Its hash must be the proven block hash.
/// @param receiptProof The trie nodes from the receipts root to the receipt.
/// @param receiptIndex The index of the transaction in the block. It is the trie key of the receipt.
/// @param transactionProof The trie nodes from the transactions root to the transaction.
/// @param transactionIndex The trie key of the transaction. It must equal `receiptIndex`.
/// @param logIndex The index of the `UserRequestForAffirmation` log inside the receipt.
struct MessageProof {
BeaconBlockHeader anchorHeader;
BeaconBlockHeader sourceHeader;
bytes32[] ancestryBranch;
bytes32[] blockHashBranch;
ForkProof sourceFork;
bytes executionHeaderRlp;
bytes[] receiptProof;
uint256 receiptIndex;
bytes[] transactionProof;
uint256 transactionIndex;
uint256 logIndex;
}
/// @notice The state of a message on this chain. A message that was never delivered, or whose every delivery
/// reverted, is `NotDelivered`.
/// @dev `InProgress` lasts only inside the call to the target. It is the mark that the bridge sets before the call.
/// There is no failed state: a failed call reverts the delivery.
enum DeliveryStatus {
NotDelivered,
InProgress,
Succeeded
}
/// @notice The topic 0 of `UserRequestForAffirmation`. A message proof matches logs against this value.
/// @dev Solidity 0.8.28 rejects `UserRequestForAffirmation.selector` in a constant. A test pins this value.
bytes32 public constant USER_REQUEST_TOPIC = keccak256("UserRequestForAffirmation(bytes32,bytes)");
/// @dev The call data types that this bridge sends and accepts.
uint8 private constant DATA_TYPE_PASS = AmbMessageCodec.DATA_TYPE_PASS;
uint8 private constant DATA_TYPE_CONFIRM = AmbMessageCodec.DATA_TYPE_CONFIRM;
/// @dev OmniBridge refuses a message whose call data starts with one of these selectors, so that the bridge cannot
/// be made to move tokens of a contract that approved it: `transfer(address,uint256)`,
/// `approve(address,uint256)`, `transferFrom(address,address,uint256)`, `approveAndCall(address,uint256,bytes)` and
/// `transferAndCall(address,uint256,bytes)`.
bytes4 private constant TRANSFER_SELECTOR = 0xa9059cbb;
bytes4 private constant APPROVE_SELECTOR = 0x095ea7b3;
bytes4 private constant TRANSFER_FROM_SELECTOR = 0x23b872dd;
bytes4 private constant TRANSFER_AND_CALL_SELECTOR = 0x4000aea0;
bytes4 private constant APPROVE_AND_CALL_SELECTOR = 0xcae9ca51;
/// @notice The call data starts with a selector that the bridge never forwards.
error ForbiddenSelector(bytes4 selector);
/// @notice Sends are closed because the cutoff time passed.
error SendCutoffReached(uint64 cutoff);
/// @notice A message is executing. Another `executeMessage` would overwrite its context.
error MessageInProgress(bytes32 messageId);
/// @notice The receipt index and the transaction index of the proof differ.
error IndexMismatch(uint256 receiptIndex, uint256 transactionIndex);
/// @notice The log event data is not the encoding of one `bytes` value.
error MalformedEventData();
/// @notice The topic holds another message identifier than the message.
error MessageIdMismatch(bytes32 topicMessageId, bytes32 encodedMessageId);
/// @notice The message identifier has another format version than this bridge reads.
error MessageVersionInvalid(bytes32 messageId);
/// @notice The message has a data type that this bridge does not send.
error UnknownDataType(uint8 dataType);
/// @notice The message names another source chain than the remote chain.
error WrongSourceChain(uint64 expected, uint256 actual);
/// @notice The message names another destination chain than this chain.
error WrongDestinationChain(uint64 expected, uint256 actual);
/// @notice The message was already delivered.
error AlreadyDelivered(bytes32 messageId);
/// @notice The call to the target failed and returned no error of its own (for example, it ran out of gas). The
/// message stays `NotDelivered`.
error TargetCallFailed(bytes32 messageId);
/// @notice The chain identifier of the deployment does not fit the 64 bits that the message format gives it.
error LocalChainIdTooLarge(uint256 chainId);
/// @notice The identifier of this chain: `block.chainid` at deployment.
uint64 public immutable localChainId;
/// @notice The identifier of the other chain.
uint64 public immutable remoteChainId;
/// @notice The bridge on the other chain.
address public immutable remoteBridge;
/// @notice Sends revert at and after this timestamp. Zero disables the cutoff. Set it at deployment only when a
/// breaking fork of the other chain is already scheduled.
uint64 public immutable sendCutoffTimestamp;
/// @notice The gate that every send calls. It refuses a send that the route cannot deliver.
IDepositGate public immutable depositGate;
/// @dev The version and the bridge part of every message identifier of this bridge.
bytes32 private immutable messageIdPrefix;
// The nonce, the flag and the sender of the context share one storage word.
/// @dev The number of messages sent. It feeds the identifier.
uint64 private _nonce;
/// @notice Whether sends are open. It starts false and `openDeposits` sets it true for good.
bool public depositsOpen;
/// @dev The sender of the message that executes now. Zero outside the call to the target.
address private _activeSender;
/// @dev The identifier of the message that executes now. Zero outside the call to the target.
bytes32 private _activeMessageId;
/// @dev The source transaction hash of the message that executes now. Zero outside the call to the target.
bytes32 private _activeTransactionHash;
mapping(bytes32 messageId => DeliveryStatus) private _deliveries;
/// @dev The `block_roots`, block hash and `historical_summaries` layout tables, in the slots that three separate
/// arrays had before (`BeaconProofVerifier.LayoutTables`).
LayoutTables private _layouts;
/// @param lightClient_ The light client of the remote chain.
/// @param remoteChainId_ The identifier of the other chain.
/// @param remoteBridge_ The bridge on the other chain.
/// @param bridgeTerms The send cutoff and the remote light client. See `BridgeTerms`.
/// @param capellaEra_ `floor(capellaForkSlot / 8192)` of the remote chain. The deploy script checks it.
/// @param depositGate_ The gate that every send calls. It must not be the zero address.
constructor(
address lightClient_,
uint64 remoteChainId_,
address remoteBridge_,
BridgeTerms memory bridgeTerms,
uint64 capellaEra_,
address depositGate_
) BeaconProofVerifier(lightClient_, capellaEra_, bridgeTerms.remoteLightClient) {
if (lightClient_ == address(0)) revert ZeroValue("lightClient");
if (remoteChainId_ == 0) revert ZeroValue("remoteChainId");
if (remoteBridge_ == address(0)) revert ZeroValue("remoteBridge");
if (depositGate_ == address(0)) revert ZeroValue("depositGate");
if (bridgeTerms.remoteLightClient == address(0)) revert ZeroValue("remoteLightClient");
uint64 localChainId_ = _toLocalChainId(block.chainid);
if (remoteChainId_ == localChainId_) revert RemoteChainIsLocalChain();
localChainId = localChainId_;
remoteChainId = remoteChainId_;
remoteBridge = remoteBridge_;
sendCutoffTimestamp = bridgeTerms.cutoffTimestamp;
depositGate = IDepositGate(depositGate_);
messageIdPrefix = AmbMessageCodec.messageIdPrefix(localChainId_, address(this));
}
/// @dev `block.chainid` as the local chain identifier of the messages, which hold it in 64 bits. A larger
/// identifier is refused rather than cut, because a cut identifier names another chain.
function _toLocalChainId(uint256 chainId) internal pure returns (uint64) {
if (chainId > type(uint64).max) revert LocalChainIdTooLarge(chainId);
return uint64(chainId);
}
// ------------------------------------------------------------------ sending
/// @inheritdoc IAMB
/// @dev `_gas` is accepted for the OmniBridge interface and ignored: delivery gives the target all the gas that is
/// left, and the gas field of the message is zero.
function requireToPassMessage(address _contract, bytes calldata _data, uint256)
external
override
returns (bytes32)
{
return _send(_contract, _data, DATA_TYPE_PASS);
}
/// @inheritdoc IAMB
/// @dev The same as `requireToPassMessage`, with the data type of the manual lane. This bridge has no manual lane.
function requireToConfirmMessage(address _contract, bytes calldata _data, uint256)
external
override
returns (bytes32)
{
return _send(_contract, _data, DATA_TYPE_CONFIRM);
}
/// @dev The checks run in this order: the lock, the cutoff, the selector, the gate. The nonce moves before the gate
/// call, so a gate that calls back cannot cause a repeated identifier. There is no gas check: the gas argument of
/// the interface is not used.
function _send(address target, bytes calldata data, uint8 dataType) private returns (bytes32 id) {
if (!depositsOpen) revert DepositsNotOpen();
if (sendCutoffTimestamp != 0 && block.timestamp >= sendCutoffTimestamp) {
revert SendCutoffReached(sendCutoffTimestamp);
}
_requireForwardableSelector(data);
uint64 nonce = _nonce;
_nonce = nonce + 1;
depositGate.admit("");
id = messageIdPrefix | bytes32(uint256(nonce));
AmbMessageCodec.Header memory header = AmbMessageCodec.Header({
messageId: id,
sender: msg.sender,
executor: target,
gasLimit: 0,
dataType: dataType,
sourceChainId: localChainId,
destinationChainId: remoteChainId
});
emit UserRequestForAffirmation(id, AmbMessageCodec.encode(header, data));
}
/// @dev Reverts when the call data starts with a selector of a token transfer or approval.
function _requireForwardableSelector(bytes calldata data) private pure {
if (data.length < 4) return;
bytes4 selector = bytes4(data[:4]);
if (
selector == TRANSFER_SELECTOR || selector == APPROVE_SELECTOR || selector == TRANSFER_FROM_SELECTOR
|| selector == TRANSFER_AND_CALL_SELECTOR || selector == APPROVE_AND_CALL_SELECTOR
) {
revert ForbiddenSelector(selector);
}
}
// ------------------------------------------------------------------ delivery
/// @notice Delivers a message that a bridge on the other chain sent, given direct evidence. Anyone may call it.
/// @dev A message executes once, with the target and data that the sender fixed, so an executor that runs ahead of
/// another does no harm. The executor pays the gas and gets no fee from the bridge. When the call to the target
/// fails, the delivery reverts with the error of the target (or `TargetCallFailed` when the target returned none),
/// and the message stays `NotDelivered`. A target with no code (an account, an address where no contract exists
/// yet, a precompile that returns nothing) receives an empty call, which the EVM counts as a success: the message
/// is `Succeeded` and `AffirmationCompleted` reports true, as on the bridge that this one mimics, and it never runs
/// again. The target is the choice of the sender, and so is that mistake.
/// @param proof The evidence.
function executeMessage(MessageProof calldata proof) external {
if (_activeMessageId != bytes32(0)) revert MessageInProgress(_activeMessageId);
if (proof.receiptIndex != proof.transactionIndex) {
revert IndexMismatch(proof.receiptIndex, proof.transactionIndex);
}
(bytes memory encoded, bytes32 topicMessageId, bytes32 sourceTransactionHash) = _provenLog(proof);
(AmbMessageCodec.Header memory header, bytes memory data) = AmbMessageCodec.decode(encoded);
_requireAcceptableMessage(header, topicMessageId);
if (_deliveries[header.messageId] != DeliveryStatus.NotDelivered) revert AlreadyDelivered(header.messageId);
_deliveries[header.messageId] = DeliveryStatus.InProgress;
_callTarget(header, data, sourceTransactionHash);
_deliveries[header.messageId] = DeliveryStatus.Succeeded;
emit AffirmationCompleted(header.sender, header.executor, header.messageId, true);
}
/// @dev Checks 1 to 7 and the log, and returns the encoded message of the log, the identifier in its topic and the
/// hash of the transaction. The identifier in the topic and the one in the message are two copies of the same value.
/// Checks 1 to 4 run here; the execution header, the receipt, the transaction and the log run in
/// `ReceiptProofLib.provenLog`, under the block hash proven here.
function _provenLog(MessageProof calldata proof)
private
view
returns (bytes memory encoded, bytes32 topicMessageId, bytes32 sourceTransactionHash)
{
_requireAncestry(proof.anchorHeader, proof.sourceHeader, proof.ancestryBranch);
_requireBlockHashBranch(
keccak256(proof.executionHeaderRlp), proof.sourceHeader, proof.blockHashBranch, proof.sourceFork
);
(topicMessageId, encoded, sourceTransactionHash) = ReceiptProofLib.provenLog(
proof.executionHeaderRlp,
proof.receiptProof,
proof.receiptIndex,
proof.transactionProof,
proof.logIndex,
remoteBridge,
USER_REQUEST_TOPIC
);
}
/// @dev Checks the message against the log and this bridge.
function _requireAcceptableMessage(AmbMessageCodec.Header memory header, bytes32 topicMessageId) private view {
if (header.messageId != topicMessageId) revert MessageIdMismatch(topicMessageId, header.messageId);
if (!AmbMessageCodec.hasValidVersion(header.messageId)) revert MessageVersionInvalid(header.messageId);
if (header.sourceChainId != remoteChainId) revert WrongSourceChain(remoteChainId, header.sourceChainId);
if (header.destinationChainId != localChainId) {
revert WrongDestinationChain(localChainId, header.destinationChainId);
}
if (header.dataType != DATA_TYPE_PASS && header.dataType != DATA_TYPE_CONFIRM) {
revert UnknownDataType(header.dataType);
}
}
/// @dev Sets the context, calls the target with all the gas that is left, and clears the context. A failed call
/// reverts the delivery with the error data of the target. The bridge does not read the code of the target: a call
/// to an address with no code succeeds with nothing run, and the delivery completes. A successful call copies no return data, so a target
/// cannot cost gas with a large answer. The error data of a failed call is copied, at the cost of the delivery that
/// reverts anyway.
function _callTarget(AmbMessageCodec.Header memory header, bytes memory data, bytes32 sourceTransactionHash)
private
{
_activeSender = header.sender;
_activeMessageId = header.messageId;
_activeTransactionHash = sourceTransactionHash;
address target = header.executor;
bool success;
assembly {
success := call(gas(), target, 0, add(data, 32), mload(data), 0, 0)
}
if (!success) _bubble(header.messageId);
_activeSender = address(0);
_activeMessageId = bytes32(0);
_activeTransactionHash = bytes32(0);
}
/// @dev Reverts with the error data of the call that just failed, or with `TargetCallFailed` when it has none.
function _bubble(bytes32 id) private pure {
assembly ("memory-safe") {
let size := returndatasize()
if size {
let pointer := mload(0x40)
returndatacopy(pointer, 0, size)
revert(pointer, size)
}
}
revert TargetCallFailed(id);
}
// ------------------------------------------------------------------ the lock
/// @notice Opens sends for good, given proof that the remote light client has stored a head.
/// @dev A message sent at slot `s` is delivered only if some block hash row covers `s`. A row starts at a stored
/// head that has an execution block hash, and the constructor of the light client stores none. So a message sent
/// before the remote light client stored its first update is lost for ever. `_verifyOpening` checks the proof.
/// After the call, the flag stays true. The call needs no key. A call after the opening returns at once, so two
/// openers do not fail each other.
/// @param proof The evidence.
function openDeposits(OpeningProof calldata proof) external {
if (depositsOpen) return;
bytes32 blockHash = _verifyOpening(proof);
depositsOpen = true;
emit DepositsOpened(proof.remoteSlot, blockHash, proof.storedSlot);
}
// ------------------------------------------------------------------ context and views
/// @inheritdoc IAMB
function messageSender() external view override returns (address) {
return _activeSender;
}
/// @inheritdoc IAMB
function messageId() external view override returns (bytes32) {
return _activeMessageId;
}
/// @inheritdoc IAMB
/// @dev The proven transaction hash of the source chain: the hash of the transaction at the index of the receipt.
function transactionHash() external view override returns (bytes32) {
return _activeTransactionHash;
}
/// @inheritdoc IAMB
/// @dev The source chain is always the remote chain, so the value follows the context: it is zero when no message
/// executes.
function messageSourceChainId() external view override returns (bytes32) {
if (_activeMessageId == bytes32(0)) return bytes32(0);
return bytes32(uint256(remoteChainId));
}
/// @inheritdoc IAMB
/// @dev True once the message was delivered. A delivery whose call fails reverts, so there is no false after an
/// attempt: false means not delivered yet.
function messageCallStatus(bytes32 id) external view override returns (bool) {
return _deliveries[id] == DeliveryStatus.Succeeded;
}
/// @notice The state of a message on this chain.
/// @param id The message identifier.
function deliveryStatus(bytes32 id) external view returns (DeliveryStatus) {
return _deliveries[id];
}
/// @inheritdoc IAMB
/// @dev Always zero: no message ends as a failure on this bridge. Kept for the OmniBridge interface.
function failedMessageDataHash(bytes32) external pure override returns (bytes32) {
return bytes32(0);
}
/// @inheritdoc IAMB
/// @dev Always zero, as `failedMessageDataHash`.
function failedMessageReceiver(bytes32) external pure override returns (address) {
return address(0);
}
/// @inheritdoc IAMB
/// @dev Always zero, as `failedMessageDataHash`.
function failedMessageSender(bytes32) external pure override returns (address) {
return address(0);
}
/// @inheritdoc IAMB
/// @dev The bridge has no gas ceiling for a message: delivery gives the target all the gas that is left. It answers
/// the largest value that the gas field of the encoding can hold, so that an OmniBridge sender that checks its gas
/// against this value passes.
function maxGasPerTx() external pure override returns (uint256) {
return type(uint32).max;
}
/// @inheritdoc IAMB
function sourceChainId() external view override returns (uint256) {
return localChainId;
}
/// @inheritdoc IAMB
function destinationChainId() external view override returns (uint256) {
return remoteChainId;
}
// ------------------------------------------------------------------ storage hook
function _layoutTables() internal view override returns (LayoutTables storage) {
return _layouts;
}
}
src/hardened/vendor/optimism/trie/MerkleTrie.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Libraries
import { Bytes } from "../Bytes.sol";
import { RLPReader } from "../rlp/RLPReader.sol";
/// @title MerkleTrie
/// @notice MerkleTrie is a small library for verifying standard Ethereum Merkle-Patricia trie
/// inclusion proofs. By default, this library assumes a hexary trie. One can change the
/// trie radix constant to support other trie radixes.
library MerkleTrie {
/// @notice Struct representing a node in the trie.
/// @custom:field encoded The RLP-encoded node.
/// @custom:field decoded The RLP-decoded node.
struct TrieNode {
bytes encoded;
RLPReader.RLPItem[] decoded;
}
/// @notice Determines the number of elements per branch node.
uint256 internal constant TREE_RADIX = 16;
/// @notice Branch nodes have TREE_RADIX elements and one value element.
uint256 internal constant BRANCH_NODE_LENGTH = TREE_RADIX + 1;
/// @notice Leaf nodes and extension nodes have two elements, a `path` and a `value`.
uint256 internal constant LEAF_OR_EXTENSION_NODE_LENGTH = 2;
/// @notice Prefix for even-nibbled extension node paths.
uint8 internal constant PREFIX_EXTENSION_EVEN = 0;
/// @notice Prefix for odd-nibbled extension node paths.
uint8 internal constant PREFIX_EXTENSION_ODD = 1;
/// @notice Prefix for even-nibbled leaf node paths.
uint8 internal constant PREFIX_LEAF_EVEN = 2;
/// @notice Prefix for odd-nibbled leaf node paths.
uint8 internal constant PREFIX_LEAF_ODD = 3;
/// @notice Verifies a proof that a given key/value pair is present in the trie.
/// @param _key Key of the node to search for, as a hex string.
/// @param _value Value of the node to search for, as a hex string.
/// @param _proof Merkle trie inclusion proof for the desired node. Unlike traditional Merkle
/// trees, this proof is executed top-down and consists of a list of RLP-encoded
/// nodes that make a path down to the target node.
/// @param _root Known root of the Merkle trie. Used to verify that the included proof is
/// correctly constructed.
/// @return valid_ Whether or not the proof is valid.
function verifyInclusionProof(
bytes memory _key,
bytes memory _value,
bytes[] memory _proof,
bytes32 _root
)
internal
pure
returns (bool valid_)
{
valid_ = Bytes.equal(_value, get(_key, _proof, _root));
}
/// @notice Retrieves the value associated with a given key.
/// @param _key Key to search for, as hex bytes.
/// @param _proof Merkle trie inclusion proof for the key.
/// @param _root Known root of the Merkle trie.
/// @return value_ Value of the key if it exists.
function get(bytes memory _key, bytes[] memory _proof, bytes32 _root) internal pure returns (bytes memory value_) {
require(_key.length > 0, "MerkleTrie: empty key");
TrieNode[] memory proof = _parseProof(_proof);
bytes memory key = Bytes.toNibbles(_key);
bytes memory currentNodeID = abi.encodePacked(_root);
uint256 currentKeyIndex = 0;
// Proof is top-down, so we start at the first element (root).
for (uint256 i = 0; i < proof.length; i++) {
TrieNode memory currentNode = proof[i];
// Key index should never exceed total key length or we'll be out of bounds.
require(currentKeyIndex <= key.length, "MerkleTrie: key index exceeds total key length");
if (currentKeyIndex == 0) {
// First proof element is always the root node.
require(
Bytes.equal(abi.encodePacked(keccak256(currentNode.encoded)), currentNodeID),
"MerkleTrie: invalid root hash"
);
} else if (currentNode.encoded.length >= 32) {
// Nodes 32 bytes or larger are hashed inside branch nodes.
require(
Bytes.equal(abi.encodePacked(keccak256(currentNode.encoded)), currentNodeID),
"MerkleTrie: invalid large internal hash"
);
} else {
// Nodes smaller than 32 bytes aren't hashed.
require(Bytes.equal(currentNode.encoded, currentNodeID), "MerkleTrie: invalid internal node hash");
}
if (currentNode.decoded.length == BRANCH_NODE_LENGTH) {
if (currentKeyIndex == key.length) {
// Value is the last element of the decoded list (for branch nodes). There's
// some ambiguity in the Merkle trie specification because bytes(0) is a
// valid value to place into the trie, but for branch nodes bytes(0) can exist
// even when the value wasn't explicitly placed there. Geth treats a value of
// bytes(0) as "key does not exist" and so we do the same.
value_ = RLPReader.readBytes(currentNode.decoded[TREE_RADIX]);
require(value_.length > 0, "MerkleTrie: value length must be greater than zero (branch)");
// Extra proof elements are not allowed.
require(i == proof.length - 1, "MerkleTrie: value node must be last node in proof (branch)");
return value_;
} else {
// We're not at the end of the key yet.
// Figure out what the next node ID should be and continue.
uint8 branchKey = uint8(key[currentKeyIndex]);
RLPReader.RLPItem memory nextNode = currentNode.decoded[branchKey];
currentNodeID = _getNodeID(nextNode);
currentKeyIndex += 1;
}
} else if (currentNode.decoded.length == LEAF_OR_EXTENSION_NODE_LENGTH) {
bytes memory path = _getNodePath(currentNode);
uint8 prefix = uint8(path[0]);
uint8 offset = 2 - (prefix % 2);
bytes memory pathRemainder = Bytes.slice(path, offset);
bytes memory keyRemainder = Bytes.slice(key, currentKeyIndex);
uint256 sharedNibbleLength = _getSharedNibbleLength(pathRemainder, keyRemainder);
// Whether this is a leaf node or an extension node, the path remainder MUST be a
// prefix of the key remainder (or be equal to the key remainder) or the proof is
// considered invalid.
require(
pathRemainder.length == sharedNibbleLength,
"MerkleTrie: path remainder must share all nibbles with key"
);
if (prefix == PREFIX_LEAF_EVEN || prefix == PREFIX_LEAF_ODD) {
// Prefix of 2 or 3 means this is a leaf node. For the leaf node to be valid,
// the key remainder must be exactly equal to the path remainder. We already
// did the necessary byte comparison, so it's more efficient here to check that
// the key remainder length equals the shared nibble length, which implies
// equality with the path remainder (since we already did the same check with
// the path remainder and the shared nibble length).
require(
keyRemainder.length == sharedNibbleLength,
"MerkleTrie: key remainder must be identical to path remainder"
);
// Our Merkle Trie is designed specifically for the purposes of the Ethereum
// state trie. Empty values are not allowed in the state trie, so we can safely
// say that if the value is empty, the key should not exist and the proof is
// invalid.
value_ = RLPReader.readBytes(currentNode.decoded[1]);
require(value_.length > 0, "MerkleTrie: value length must be greater than zero (leaf)");
// Extra proof elements are not allowed.
require(i == proof.length - 1, "MerkleTrie: value node must be last node in proof (leaf)");
return value_;
} else if (prefix == PREFIX_EXTENSION_EVEN || prefix == PREFIX_EXTENSION_ODD) {
// Prefix of 0 or 1 means this is an extension node. We move onto the next node
// in the proof and increment the key index by the length of the path remainder
// which is equal to the shared nibble length.
currentNodeID = _getNodeID(currentNode.decoded[1]);
currentKeyIndex += sharedNibbleLength;
} else {
revert("MerkleTrie: received a node with an unknown prefix");
}
} else {
revert("MerkleTrie: received an unparseable node");
}
}
revert("MerkleTrie: ran out of proof elements");
}
/// @notice Parses an array of proof elements into a new array that contains both the original
/// encoded element and the RLP-decoded element.
/// @param _proof Array of proof elements to parse.
/// @return proof_ Proof parsed into easily accessible structs.
function _parseProof(bytes[] memory _proof) private pure returns (TrieNode[] memory proof_) {
uint256 length = _proof.length;
proof_ = new TrieNode[](length);
for (uint256 i = 0; i < length;) {
proof_[i] = TrieNode({ encoded: _proof[i], decoded: RLPReader.readList(_proof[i]) });
unchecked {
++i;
}
}
}
/// @notice Picks out the ID for a node. Node ID is referred to as the "hash" within the
/// specification, but nodes < 32 bytes are not actually hashed.
/// @param _node Node to pull an ID for.
/// @return id_ ID for the node, depending on the size of its contents.
function _getNodeID(RLPReader.RLPItem memory _node) private pure returns (bytes memory id_) {
id_ = _node.length < 32 ? RLPReader.readRawBytes(_node) : RLPReader.readBytes(_node);
}
/// @notice Gets the path for a leaf or extension node.
/// @param _node Node to get a path for.
/// @return nibbles_ Node path, converted to an array of nibbles.
function _getNodePath(TrieNode memory _node) private pure returns (bytes memory nibbles_) {
nibbles_ = Bytes.toNibbles(RLPReader.readBytes(_node.decoded[0]));
}
/// @notice Utility; determines the number of nibbles shared between two nibble arrays.
/// @param _a First nibble array.
/// @param _b Second nibble array.
/// @return shared_ Number of shared nibbles.
function _getSharedNibbleLength(bytes memory _a, bytes memory _b) private pure returns (uint256 shared_) {
uint256 max = (_a.length < _b.length) ? _a.length : _b.length;
for (; shared_ < max && _a[shared_] == _b[shared_];) {
unchecked {
++shared_;
}
}
}
}
src/hardened/ForkShape.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {SSZ} from "./SSZ.sol";
/// @title ForkShape
/// @notice The one rule that decides which fork versions the bridge accepts, on both chains. It looks at the shape of the
/// `BeaconState` tree, never at the name of a fork version.
/// @dev A shape is a plain tree depth (5, 6 or 7) or the progressive form of Gloas, marked by `PROGRESSIVE`. A shape is
/// allowed when it is in the list that `allowedShapes` returns. That list is the only place where the set is written.
/// Both paths of `BeaconForkGate` read it: the path with EIP-4788 evidence (`judge`) and the path with the registry
/// (`isAllowed`). A new allowed shape added here reaches both paths and `allowedShapes` at once, so they cannot drift.
///
/// The evidence of one shape has two branches under the same state root:
/// - The version branch proves `fork.current_version`. In a plain tree of depth d the leaf sits at
/// `((2**d + 3) * 4) + 1` and the branch has d + 2 entries. In the progressive form it sits at 169 with 7 entries.
/// - The genesis validators root branch proves `genesis_validators_root` (field 1) at its position for that shape: `2**d + 1` with d
/// entries, or node 40 with 5 entries. The leaf is the value that the gate holds as an immutable.
/// A version branch of 7 entries fits both plain depth 5 and the progressive form. `judge` tries each and takes the
/// first for which both branches verify.
///
/// Trade-off: the rule judges the shape, not the meaning of the fields. A future fork that reorders fields at the same
/// depth passes the gate. The light client then fails closed, because its own proofs check fixed positions.
library ForkShape {
/// @notice The marker of the progressive `BeaconState` (Gloas on).
uint8 internal constant PROGRESSIVE = 255;
/// @notice The smallest depth for which a seal proof is looked at. Lower depths land above the fields.
uint8 internal constant MIN_SEAL_DEPTH = 5;
/// @notice The largest depth for which a seal proof is looked at.
uint8 internal constant MAX_SEAL_DEPTH = 31;
/// @notice The depth of the three field `Fork` container.
uint256 internal constant FORK_DEPTH = 2;
/// @dev The generalized index of `fork.current_version` in the progressive state: node 42 times 4, plus 1.
uint256 private constant PROGRESSIVE_VERSION_GINDEX = 169;
/// @dev The generalized index of `genesis_validators_root` (chunk 1) in the progressive state.
uint256 private constant PROGRESSIVE_GENESIS_VALIDATORS_ROOT_GINDEX = 40;
/// @dev Branch length of the version leaf in the progressive state: 5 state levels and the `Fork` container.
uint256 private constant PROGRESSIVE_VERSION_LENGTH = 7;
/// @dev Branch length of the genesis validators root leaf in the progressive state.
uint256 private constant PROGRESSIVE_GENESIS_VALIDATORS_ROOT_LENGTH = 5;
/// @dev The position of `fork` among the `BeaconState` fields.
uint256 private constant FORK_FIELD_INDEX = 3;
/// @dev The position of `genesis_validators_root` among the `BeaconState` fields.
uint256 private constant GENESIS_VALIDATORS_ROOT_FIELD_INDEX = 1;
/// @notice The result of judging evidence.
enum Verdict {
/// @dev A shape in the allowed set, with both branches valid.
Allowed,
/// @dev No candidate shape has a valid version branch.
VersionProofInvalid,
/// @dev The version branch is valid for a candidate shape, but its genesis validators root branch is not.
GenesisValidatorsRootProofInvalid,
/// @dev The version branch length fits no allowed shape.
ShapeNotAllowed
}
/// @notice The allowed shapes, in the order in which `judge` tries them.
function allowedShapes() internal pure returns (uint8[] memory shapes) {
shapes = new uint8[](4);
shapes[0] = 5;
shapes[1] = 6;
shapes[2] = 7;
shapes[3] = PROGRESSIVE;
}
/// @notice Whether a shape is in the allowed set. The registry path uses this check.
/// @param shape A plain depth, or `PROGRESSIVE`.
function isAllowed(uint8 shape) internal pure returns (bool) {
uint8[] memory shapes = allowedShapes();
for (uint256 i = 0; i < shapes.length; i++) {
if (shapes[i] == shape) return true;
}
return false;
}
/// @notice The generalized index of `fork.current_version` for an allowed shape.
function versionGindex(uint8 shape) internal pure returns (uint256) {
if (shape == PROGRESSIVE) return PROGRESSIVE_VERSION_GINDEX;
return plainVersionGindex(shape);
}
/// @notice The generalized index of `fork.current_version` in a plain tree of any depth.
function plainVersionGindex(uint256 depth) internal pure returns (uint256) {
return (((uint256(1) << depth) + FORK_FIELD_INDEX) * 4) + 1;
}
/// @notice The generalized index of `genesis_validators_root` for an allowed shape.
function genesisValidatorsRootGindex(uint8 shape) internal pure returns (uint256) {
if (shape == PROGRESSIVE) return PROGRESSIVE_GENESIS_VALIDATORS_ROOT_GINDEX;
return (uint256(1) << shape) + GENESIS_VALIDATORS_ROOT_FIELD_INDEX;
}
/// @notice The number of entries in the version branch of an allowed shape.
function versionBranchLength(uint8 shape) internal pure returns (uint256) {
if (shape == PROGRESSIVE) return PROGRESSIVE_VERSION_LENGTH;
return uint256(shape) + FORK_DEPTH;
}
/// @notice The number of entries in the genesis validators root branch of an allowed shape.
function genesisValidatorsRootBranchLength(uint8 shape) internal pure returns (uint256) {
if (shape == PROGRESSIVE) return PROGRESSIVE_GENESIS_VALIDATORS_ROOT_LENGTH;
return shape;
}
/// @notice The tree depth that a version branch length implies, or zero when the length is below the `Fork` depth.
function depthOfVersionBranch(uint256 length) internal pure returns (uint256) {
if (length < FORK_DEPTH) return 0;
return length - FORK_DEPTH;
}
/// @notice Judges the evidence of the EIP-4788 path.
/// @param stateRoot The state root of the header that the beacon roots contract vouches for.
/// @param version The claimed `fork.current_version`.
/// @param versionBranch The branch of the version leaf, deepest first.
/// @param genesisValidatorsRootBranch The branch of `genesis_validators_root`, deepest first.
/// @param genesisValidatorsRoot The value that the genesis validators root leaf must hold.
/// @return verdict The result.
/// @return shape The shape that was proven. Zero unless the verdict is `Allowed`.
function judge(
bytes32 stateRoot,
bytes4 version,
bytes32[] memory versionBranch,
bytes32[] memory genesisValidatorsRootBranch,
bytes32 genesisValidatorsRoot
) internal pure returns (Verdict verdict, uint8 shape) {
uint8[] memory shapes = allowedShapes();
bool anyCandidate;
bool versionProven;
for (uint256 i = 0; i < shapes.length; i++) {
uint8 candidate = shapes[i];
if (versionBranch.length != versionBranchLength(candidate)) continue;
anyCandidate = true;
if (!SSZ.isValidBranchMemory(bytes32(version), versionBranch, versionGindex(candidate), stateRoot)) continue;
versionProven = true;
if (_genesisValidatorsRootHolds(candidate, genesisValidatorsRootBranch, genesisValidatorsRoot, stateRoot)) return (Verdict.Allowed, candidate);
}
if (!anyCandidate) return (Verdict.ShapeNotAllowed, 0);
if (versionProven) return (Verdict.GenesisValidatorsRootProofInvalid, 0);
return (Verdict.VersionProofInvalid, 0);
}
/// @notice Whether a version branch is valid at the plain position of `depth`. A seal uses it for a depth outside
/// the allowed set. The branch length must equal `depth + 2`.
/// @param stateRoot The state root.
/// @param version The claimed version.
/// @param versionBranch The branch of the version leaf.
/// @param depth The plain tree depth that the branch length implies.
function provesPlainVersion(bytes32 stateRoot, bytes4 version, bytes32[] memory versionBranch, uint256 depth)
internal
pure
returns (bool)
{
return SSZ.isValidBranchMemory(bytes32(version), versionBranch, plainVersionGindex(depth), stateRoot);
}
/// @dev Whether the genesis validators root branch has the length of the shape and proves the genesis validators root.
function _genesisValidatorsRootHolds(uint8 shape, bytes32[] memory genesisValidatorsRootBranch, bytes32 genesisValidatorsRoot, bytes32 stateRoot)
private
pure
returns (bool)
{
if (genesisValidatorsRootBranch.length != genesisValidatorsRootBranchLength(shape)) return false;
return SSZ.isValidBranchMemory(genesisValidatorsRoot, genesisValidatorsRootBranch, genesisValidatorsRootGindex(shape), stateRoot);
}
}
src/hardened/IDepositGate.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title IDepositGate
/// @notice A check that the vault runs first in `deposit`. A gate that reverts refuses the deposit.
interface IDepositGate {
/// @notice Admits a deposit, or reverts.
/// @param evidence Gate-specific evidence. The vault passes the `gateEvidence` of the deposit unchanged.
function admit(bytes calldata evidence) external;
}
src/hardened/IBeaconLightClient.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title IBeaconLightClient
/// @notice The part of the light client that the vault reads.
interface IBeaconLightClient {
/// @notice The finalized beacon header root stored for a slot, or zero.
/// @param slot The beacon slot.
function headers(uint64 slot) external view returns (bytes32);
/// @notice The execution block hash stored for the head at a slot, or zero.
/// @param slot The beacon slot.
function executionBlockHashes(uint64 slot) external view returns (bytes32);
/// @notice Whether the execution block hash sits in a finalized beacon header.
/// @param blockHash The execution block hash.
function isFinalizedExecutionBlock(bytes32 blockHash) external view returns (bool);
/// @notice The genesis validators root of the tracked chain. A fork proof of a state of that chain must prove it.
function genesisValidatorsRoot() external view returns (bytes32);
}
src/hardened/vendor/optimism/rlp/RLPReader.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
// Libraries
import {
EmptyItem,
UnexpectedString,
InvalidDataRemainder,
ContentLengthMismatch,
InvalidHeader,
UnexpectedList
} from "./RLPErrors.sol";
/// @custom:attribution https://github.com/hamdiallam/Solidity-RLP
/// @title RLPReader
/// @notice RLPReader is a library for parsing RLP-encoded byte arrays into Solidity types. Adapted
/// from Solidity-RLP (https://github.com/hamdiallam/Solidity-RLP) by Hamdi Allam with
/// various tweaks to improve readability.
library RLPReader {
/// @notice Custom pointer type to avoid confusion between pointers and uint256s.
type MemoryPointer is uint256;
/// @notice RLP item types.
/// @custom:value DATA_ITEM Represents an RLP data item (NOT a list).
/// @custom:value LIST_ITEM Represents an RLP list item.
enum RLPItemType {
DATA_ITEM,
LIST_ITEM
}
/// @notice Struct representing an RLP item.
/// @custom:field length Length of the RLP item.
/// @custom:field ptr Pointer to the RLP item in memory.
struct RLPItem {
uint256 length;
MemoryPointer ptr;
}
/// @notice Max list length that this library will accept.
uint256 internal constant MAX_LIST_LENGTH = 32;
/// @notice Converts bytes to a reference to memory position and length.
/// @param _in Input bytes to convert.
/// @return out_ Output memory reference.
function toRLPItem(bytes memory _in) internal pure returns (RLPItem memory out_) {
// Empty arrays are not RLP items.
if (_in.length == 0) revert EmptyItem();
MemoryPointer ptr;
assembly {
ptr := add(_in, 32)
}
out_ = RLPItem({ length: _in.length, ptr: ptr });
}
/// @notice Reads an RLP list value into a list of RLP items.
/// @param _in RLP list value.
/// @return out_ Decoded RLP list items.
function readList(RLPItem memory _in) internal pure returns (RLPItem[] memory out_) {
(uint256 listOffset, uint256 listLength, RLPItemType itemType) = _decodeLength(_in);
if (itemType != RLPItemType.LIST_ITEM) revert UnexpectedString();
if (listOffset + listLength != _in.length) revert InvalidDataRemainder();
// Solidity in-memory arrays can't be increased in size, but *can* be decreased in size by
// writing to the length. Since we can't know the number of RLP items without looping over
// the entire input, we'd have to loop twice to accurately size this array. It's easier to
// simply set a reasonable maximum list length and decrease the size before we finish.
out_ = new RLPItem[](MAX_LIST_LENGTH);
uint256 itemCount = 0;
uint256 offset = listOffset;
while (offset < _in.length) {
(uint256 itemOffset, uint256 itemLength,) = _decodeLength(
RLPItem({ length: _in.length - offset, ptr: MemoryPointer.wrap(MemoryPointer.unwrap(_in.ptr) + offset) })
);
// We don't need to check itemCount < out.length explicitly because Solidity already
// handles this check on our behalf, we'd just be wasting gas.
out_[itemCount] = RLPItem({
length: itemLength + itemOffset,
ptr: MemoryPointer.wrap(MemoryPointer.unwrap(_in.ptr) + offset)
});
itemCount += 1;
offset += itemOffset + itemLength;
}
// Decrease the array size to match the actual item count.
assembly {
mstore(out_, itemCount)
}
}
/// @notice Reads an RLP list value into a list of RLP items.
/// @param _in RLP list value.
/// @return out_ Decoded RLP list items.
function readList(bytes memory _in) internal pure returns (RLPItem[] memory out_) {
out_ = readList(toRLPItem(_in));
}
/// @notice Reads an RLP bytes value into bytes.
/// @param _in RLP bytes value.
/// @return out_ Decoded bytes.
function readBytes(RLPItem memory _in) internal pure returns (bytes memory out_) {
(uint256 itemOffset, uint256 itemLength, RLPItemType itemType) = _decodeLength(_in);
if (itemType != RLPItemType.DATA_ITEM) revert UnexpectedList();
if (_in.length != itemOffset + itemLength) revert InvalidDataRemainder();
out_ = _copy(_in.ptr, itemOffset, itemLength);
}
/// @notice Reads an RLP bytes value into bytes.
/// @param _in RLP bytes value.
/// @return out_ Decoded bytes.
function readBytes(bytes memory _in) internal pure returns (bytes memory out_) {
out_ = readBytes(toRLPItem(_in));
}
/// @notice Reads the raw bytes of an RLP item.
/// @param _in RLP item to read.
/// @return out_ Raw RLP bytes.
function readRawBytes(RLPItem memory _in) internal pure returns (bytes memory out_) {
out_ = _copy(_in.ptr, 0, _in.length);
}
/// @notice Decodes the length of an RLP item.
/// @param _in RLP item to decode.
/// @return offset_ Offset of the encoded data.
/// @return length_ Length of the encoded data.
/// @return type_ RLP item type (LIST_ITEM or DATA_ITEM).
function _decodeLength(RLPItem memory _in)
private
pure
returns (uint256 offset_, uint256 length_, RLPItemType type_)
{
// Short-circuit if there's nothing to decode, note that we perform this check when
// the user creates an RLP item via toRLPItem, but it's always possible for them to bypass
// that function and create an RLP item directly. So we need to check this anyway.
if (_in.length == 0) revert EmptyItem();
MemoryPointer ptr = _in.ptr;
uint256 prefix;
assembly {
prefix := byte(0, mload(ptr))
}
if (prefix <= 0x7f) {
// Single byte.
return (0, 1, RLPItemType.DATA_ITEM);
} else if (prefix <= 0xb7) {
// Short string.
// slither-disable-next-line variable-scope
uint256 strLen = prefix - 0x80;
if (_in.length <= strLen) revert ContentLengthMismatch();
bytes1 firstByteOfContent;
assembly {
firstByteOfContent := and(mload(add(ptr, 1)), shl(248, 0xff))
}
if (strLen == 1 && firstByteOfContent < 0x80) revert InvalidHeader();
return (1, strLen, RLPItemType.DATA_ITEM);
} else if (prefix <= 0xbf) {
// Long string.
uint256 lenOfStrLen = prefix - 0xb7;
if (_in.length <= lenOfStrLen) revert ContentLengthMismatch();
bytes1 firstByteOfContent;
assembly {
firstByteOfContent := and(mload(add(ptr, 1)), shl(248, 0xff))
}
if (firstByteOfContent == 0x00) revert InvalidHeader();
uint256 strLen;
assembly {
strLen := shr(sub(256, mul(8, lenOfStrLen)), mload(add(ptr, 1)))
}
if (strLen <= 55) revert InvalidHeader();
if (_in.length <= lenOfStrLen + strLen) revert ContentLengthMismatch();
return (1 + lenOfStrLen, strLen, RLPItemType.DATA_ITEM);
} else if (prefix <= 0xf7) {
// Short list.
// slither-disable-next-line variable-scope
uint256 listLen = prefix - 0xc0;
if (_in.length <= listLen) revert ContentLengthMismatch();
return (1, listLen, RLPItemType.LIST_ITEM);
} else {
// Long list.
uint256 lenOfListLen = prefix - 0xf7;
if (_in.length <= lenOfListLen) revert ContentLengthMismatch();
bytes1 firstByteOfContent;
assembly {
firstByteOfContent := and(mload(add(ptr, 1)), shl(248, 0xff))
}
if (firstByteOfContent == 0x00) revert InvalidHeader();
uint256 listLen;
assembly {
listLen := shr(sub(256, mul(8, lenOfListLen)), mload(add(ptr, 1)))
}
if (listLen <= 55) revert InvalidHeader();
if (_in.length <= lenOfListLen + listLen) revert ContentLengthMismatch();
return (1 + lenOfListLen, listLen, RLPItemType.LIST_ITEM);
}
}
/// @notice Copies the bytes from a memory location.
/// @param _src Pointer to the location to read from.
/// @param _offset Offset to start reading from.
/// @param _length Number of bytes to read.
/// @return out_ Copied bytes.
function _copy(MemoryPointer _src, uint256 _offset, uint256 _length) private pure returns (bytes memory out_) {
out_ = new bytes(_length);
if (_length == 0) {
return out_;
}
// Mostly based on Solidity's copy_memory_to_memory:
// https://github.com/ethereum/solidity/blob/34dd30d71b4da730488be72ff6af7083cf2a91f6/libsolidity/codegen/YulUtilFunctions.cpp#L102-L114
uint256 src = MemoryPointer.unwrap(_src) + _offset;
assembly {
let dest := add(out_, 32)
let i := 0
for { } lt(i, _length) { i := add(i, 32) } { mstore(add(dest, i), mload(add(src, i))) }
if gt(i, _length) { mstore(add(dest, _length), 0) }
}
}
}
src/hardened/IAMB.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title IAMB
/// @notice The Arbitrary Message Bridge interface, as OmniBridge defines it (`omni/omnibridge`,
/// `contracts/interfaces/IAMB.sol`). `MessageBridge` implements it and adds `executeMessage`. The mediator codes
/// against this interface only and never calls `executeMessage`.
/// @dev `UserRequestForSignature` and `RelayedMessage` stay in the interface for compatibility. A bridge without
/// validators never emits them.
interface IAMB {
/// @notice Emitted by every send. `encodedData` is the Arbitrary Message Bridge message encoding.
event UserRequestForAffirmation(bytes32 indexed messageId, bytes encodedData);
/// @notice Never emitted by a bridge without validators.
event UserRequestForSignature(bytes32 indexed messageId, bytes encodedData);
/// @notice Emitted on every execution of a message. `MessageBridge` emits it only for a delivery that succeeded: a
/// delivery whose call fails reverts. So `status` is always true there.
event AffirmationCompleted(
address indexed sender, address indexed executor, bytes32 indexed messageId, bool status
);
/// @notice Never emitted by a bridge without validators.
event RelayedMessage(address indexed sender, address indexed executor, bytes32 indexed messageId, bool status);
/// @notice The sender of the message on the other chain. Set only during the call to the target.
function messageSender() external view returns (address);
/// @notice The ceiling of the gas that a message may ask for. `MessageBridge` reads no gas from a message and answers
/// the width of the gas field.
function maxGasPerTx() external view returns (uint256);
/// @notice The source transaction hash of the message. Set only during the call to the target.
function transactionHash() external view returns (bytes32);
/// @notice The identifier of the message. Set only during the call to the target.
function messageId() external view returns (bytes32);
/// @notice The identifier of the chain that sent the message. Set only during the call to the target.
function messageSourceChainId() external view returns (bytes32);
/// @notice Whether the call to the target of a message succeeded. On `MessageBridge`: whether the message was
/// delivered.
function messageCallStatus(bytes32 _messageId) external view returns (bool);
/// @notice The hash of the data of a message whose call failed. Always zero on `MessageBridge`, where a failed call
/// reverts the delivery.
function failedMessageDataHash(bytes32 _messageId) external view returns (bytes32);
/// @notice The target of a message whose call failed.
function failedMessageReceiver(bytes32 _messageId) external view returns (address);
/// @notice The sender of a message whose call failed.
function failedMessageSender(bytes32 _messageId) external view returns (address);
/// @notice Sends a message to `_contract` on the other chain.
/// @param _contract The target on the other chain.
/// @param _data The call data.
/// @param _gas The gas that the call to the target gets. `MessageBridge` ignores it: the target gets all the gas of
/// the delivery.
/// @return The message identifier.
function requireToPassMessage(address _contract, bytes calldata _data, uint256 _gas) external returns (bytes32);
/// @notice The same as `requireToPassMessage`. This bridge has no separate manual lane.
function requireToConfirmMessage(address _contract, bytes calldata _data, uint256 _gas) external returns (bytes32);
/// @notice The identifier of this chain.
function sourceChainId() external view returns (uint256);
/// @notice The identifier of the other chain.
function destinationChainId() external view returns (uint256);
}
src/hardened/ReceiptProofLib.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {MerkleTrie} from "./vendor/optimism/trie/MerkleTrie.sol";
import {RLPReader} from "./vendor/optimism/rlp/RLPReader.sol";
import {ReceiptLogs} from "./ReceiptLogs.sol";
import {BeaconProofVerifier} from "./BeaconProofVerifier.sol";
/// @title ReceiptProofLib
/// @notice The execution layer checks of a delivery of the message bridge: the receipt, the transaction and the log of a
/// message (checks 5 to 7 and the log of `executeMessage`). All of it is pure: it reads only its arguments.
/// @dev An external library, linked into `MessageBridge`. It exists so that each contract creation of the bridge stays
/// under the per-transaction gas cap of EIP-7825 (16,777,216): a library is deployed by a transaction of its own. A linked
/// library has no owner and no storage, and its address is fixed in the bytecode of the bridge, so the bridge stays
/// immutable. It reverts with the errors of `BeaconProofVerifier` (and `MalformedEventData` of the bridge, declared here
/// with the same signature), so the errors of a delivery are the same as before the split.
library ReceiptProofLib {
/// @notice The log event data is not the encoding of one `bytes` value. The same error as
/// `MessageBridge.MalformedEventData`.
error MalformedEventData();
/// @dev The index of `transactionsRoot` in the execution block header list.
uint256 internal constant TRANSACTIONS_ROOT_FIELD = 4;
/// @dev The index of `receiptsRoot` in the execution block header list.
uint256 internal constant RECEIPTS_ROOT_FIELD = 5;
/// @notice The receipt, the transaction and the log of a message, under an execution header whose hash the caller
/// proved. Returns the identifier in the topic of the log, the encoded message of its data and the hash of the
/// transaction at the index of the receipt.
/// @dev Checks 5 to 7, then the log: the header roots, the receipt (which must record success), the transaction at
/// the same trie key, the log at `logIndex`, its emitter (`emitter`), its topic 0 (`topic`) and two topics, and the
/// event data (one `bytes` value in its one encoding). The caller checks `receiptIndex == transactionIndex` first.
function provenLog(
bytes calldata executionHeaderRlp,
bytes[] calldata receiptProof,
uint256 receiptIndex,
bytes[] calldata transactionProof,
uint256 logIndex,
address emitter,
bytes32 topic
) external pure returns (bytes32 topicMessageId, bytes memory encoded, bytes32 sourceTransactionHash) {
bytes memory receipt;
(receipt, sourceTransactionHash) =
_receiptAndTransaction(executionHeaderRlp, receiptProof, receiptIndex, transactionProof);
(topicMessageId, encoded) = _messageOf(receiptLog(receipt, logIndex), emitter, topic);
}
/// @dev Checks 5 and 6: the receipt and the hash of the transaction at the trie key `index`, under the roots of the
/// execution header.
function _receiptAndTransaction(
bytes calldata executionHeaderRlp,
bytes[] calldata receiptProof,
uint256 index,
bytes[] calldata transactionProof
) private pure returns (bytes memory receipt, bytes32 transactionHash) {
RLPReader.RLPItem[] memory headerItems = RLPReader.readList(executionHeaderRlp);
bytes32 receiptsRoot = headerRoot(headerItems, RECEIPTS_ROOT_FIELD);
bytes32 transactionsRoot = headerRoot(headerItems, TRANSACTIONS_ROOT_FIELD);
bytes memory key = encodeUint(index);
receipt = MerkleTrie.get(key, receiptProof, receiptsRoot);
transactionHash = keccak256(MerkleTrie.get(key, transactionProof, transactionsRoot));
}
/// @dev Checks the emitter and the topics of a log, then returns the identifier of its topic and the message of
/// its data.
function _messageOf(RLPReader.RLPItem memory log, address emitter, bytes32 topic)
private
pure
returns (bytes32 topicMessageId, bytes memory encoded)
{
RLPReader.RLPItem[] memory logFields = logFieldsOf(log);
requireEmitter(logFields[0], emitter);
RLPReader.RLPItem[] memory topics = RLPReader.readList(logFields[1]);
if (topics.length == 0) revert BeaconProofVerifier.WrongEventTopic(bytes32(0));
bytes32 topic0 = toBytes32(RLPReader.readBytes(topics[0]));
if (topic0 != topic) revert BeaconProofVerifier.WrongEventTopic(topic0);
if (topics.length != 2) revert BeaconProofVerifier.MalformedLog();
topicMessageId = toBytes32(RLPReader.readBytes(topics[1]));
encoded = decodeBytes(RLPReader.readBytes(logFields[2]));
}
// ------------------------------------------------------------------ steps (internal, also used by tests)
/// @dev A 32-byte root of the execution header: the item at `field`. Reverts on a short header or a wrong width.
function headerRoot(RLPReader.RLPItem[] memory fields, uint256 field) internal pure returns (bytes32) {
if (fields.length <= field) revert BeaconProofVerifier.MalformedExecutionHeader();
bytes memory root = RLPReader.readBytes(fields[field]);
if (root.length != 32) revert BeaconProofVerifier.MalformedExecutionHeader();
return bytes32(root);
}
/// @dev Checks 6 and 7, up to the log. The receipt is an EIP-2718 envelope. It must record success. Returns the
/// log at `logIndex`. The receipt may hold more than 32 logs.
function receiptLog(bytes memory receipt, uint256 logIndex) internal pure returns (RLPReader.RLPItem memory) {
RLPReader.RLPItem[] memory fields = RLPReader.readList(receiptPayload(receipt));
if (fields.length != 4) revert BeaconProofVerifier.MalformedReceipt();
bytes memory status = RLPReader.readBytes(fields[0]);
if (status.length != 1 || status[0] != 0x01) revert BeaconProofVerifier.ReceiptFailed();
(bool logFound, RLPReader.RLPItem memory log, uint256 logCount) = ReceiptLogs.itemAt(fields[3], logIndex);
if (!logFound) revert BeaconProofVerifier.LogIndexOutOfRange(logIndex, logCount);
return log;
}
/// @dev The three fields of a log: emitter, topics and data.
function logFieldsOf(RLPReader.RLPItem memory log) internal pure returns (RLPReader.RLPItem[] memory fields) {
fields = RLPReader.readList(log);
if (fields.length != 3) revert BeaconProofVerifier.MalformedLog();
}
/// @dev Requires that the emitter item of a log is `expected`.
function requireEmitter(RLPReader.RLPItem memory emitterItem, address expected) internal pure {
bytes memory emitter = RLPReader.readBytes(emitterItem);
if (emitter.length != 20) revert BeaconProofVerifier.MalformedLog();
address emitterAddress = address(bytes20(emitter));
if (emitterAddress != expected) revert BeaconProofVerifier.WrongEmitter(expected, emitterAddress);
}
/// @dev Reads the event data, which is `abi.encode(bytes)`: the offset 32, the length, the bytes padded to a word.
/// Any other layout is refused, so one message has one encoding.
function decodeBytes(bytes memory eventData) internal pure returns (bytes memory) {
if (eventData.length < 64) revert MalformedEventData();
(uint256 offset, uint256 length) = abi.decode(eventData, (uint256, uint256));
if (offset != 32) revert MalformedEventData();
if (eventData.length != 64 + ((length + 31) / 32) * 32) revert MalformedEventData();
return abi.decode(eventData, (bytes));
}
/// @dev Strips the EIP-2718 type byte. Legacy receipts start with a list prefix (at least 0xc0). The result is an
/// RLP item that points one byte into the receipt, so no byte is copied. A receipt of only a type byte gives an
/// item of length zero, which the reader refuses.
function receiptPayload(bytes memory receipt) internal pure returns (RLPReader.RLPItem memory payload) {
if (receipt.length == 0) revert BeaconProofVerifier.MalformedReceipt();
uint8 first = uint8(receipt[0]);
payload = RLPReader.toRLPItem(receipt);
if (first >= 0xc0) return payload;
if (first < 0x01 || first > 0x04) revert BeaconProofVerifier.MalformedReceipt();
payload.length -= 1;
payload.ptr = RLPReader.MemoryPointer.wrap(RLPReader.MemoryPointer.unwrap(payload.ptr) + 1);
}
function toBytes32(bytes memory value) internal pure returns (bytes32) {
if (value.length != 32) revert BeaconProofVerifier.MalformedLog();
return bytes32(value);
}
/// @dev The RLP encoding of an unsigned integer, which is the receipts trie key of a transaction index.
function encodeUint(uint256 value) internal pure returns (bytes memory) {
if (value == 0) return hex"80";
if (value < 0x80) return abi.encodePacked(uint8(value));
uint256 length;
for (uint256 rest = value; rest > 0; rest >>= 8) {
length++;
}
bytes memory encoded = new bytes(length + 1);
encoded[0] = bytes1(uint8(0x80 + length));
for (uint256 i = 0; i < length; i++) {
encoded[length - i] = bytes1(uint8(value >> (8 * i)));
}
return encoded;
}
}
src/hardened/BeaconProofVerifier.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {IBeaconLightClient} from "./IBeaconLightClient.sol";
import {BeaconBlockHeader, SSZ} from "./SSZ.sol";
import {OpeningProofLib} from "./OpeningProofLib.sol";
import {BeaconLayoutLib, ERA_SLOTS, ERA_DEPTH, HISTORICAL_LIST_DEPTH} from "./BeaconLayoutLib.sol";
/// @title BeaconProofVerifier
/// @notice The proof checks that every contract of this bridge shares: it reads a log of the other chain through the
/// light client. It holds the anchor, ancestry and block hash checks, the fork layout table, the receipt and log
/// decoding, and the opening proof of the deposit lock. A contract on top of it adds the check of its own log.
/// @dev Fork layouts. The generalized indices of `state.block_roots`, of `state.historical_summaries` and of the
/// execution block hash depend on the fork of the source chain. The contract holds no fixed table. Anyone may add a
/// layout with `addBlockRootsLayout`, `addHistoricalSummariesLayout` and `addBlockHashLayout`. Two checks guard each
/// call. First, the candidate must be the position of the named field itself in a state or body tree of a known shape
/// (see the position rules below). Second, the chain's own stored data must prove it: the candidate position must map
/// stored header roots (or the stored execution block hash) to the stored state (or body) root.
///
/// The first check is needed because the second is not enough alone. Other fields hold values that a block proposer
/// chooses: the list `eth1_data_votes` has the same tree shape as `block_roots`, and `graffiti` or
/// `eth1_data.block_hash` can hold a copy of the execution block hash. A proposer could place stored header roots or
/// a stored block hash there, get that position accepted, and then forge logs. So only the position of the real field
/// is accepted.
///
/// Gloas. From Gloas on, `BeaconState` is a progressive container (EIP-7495, EIP-7916), so a field no longer sits at
/// `2**depth + index`. Its position is one fixed number, which later forks keep. `block_roots` sits at 352 and
/// `historical_summaries` at 2950. The position rules take those two numbers next to the depth rule, and no other
/// number of a deeper tree: the rule for an older fork is not looser. The body of a Gloas block holds a bid and no payload,
/// so no layout position of the block hash exists for a Gloas block. A message source whose state has the progressive
/// shape is a beacon block B after the execution block X, and the fixed index 2856 (the bid `parent_block_hash` of B)
/// must equal the hash of X.
///
/// The fork rule comes from proof, not from a date. The contract holds no fork slot. Each message carries a `ForkProof` of
/// the state of its source header, and each block hash layout evidence carries one of the state of its header. The proof
/// is judged by `ForkShape.judge`, the rule that `BeaconForkGate` applies to deposits, with the genesis validators root of
/// the light client. The proven shape picks the rule: the progressive shape takes the bid rule, a plain depth takes the
/// validated payload layout. A shape outside `ForkShape.allowedShapes` has no accepted proof, so a block of a fork on
/// which the gate seals is never proven. The `block_roots` and `historical_summaries` position rules read the same list.
/// So the gate and this contract follow one list, and a fork takes effect here with its first block, at whatever slot it
/// activates.
///
/// Ancestry has two paths, chosen from the two slots. A block at most 8192 slots below the anchor is proven through
/// `state.block_roots`. An older block is proven through `state.historical_summaries`, which holds the root of every
/// completed era of 8192 block roots since Capella. So a stored head may be any distance past the one before it.
/// A layout is usable only for the slots between the first and the last slot at which it was validated. A range
/// never covers a slot where another position was validated, and ranges of different positions never overlap. So a
/// position validated, then replaced, then validated again leaves the slots between without a layout, and each
/// lookup has one answer. Layouts move only when a container crosses a power-of-two field count; then a new route
/// (light client and bridge) is deployed beside the old one, and the old route keeps paying what it can still prove.
/// This is the immutability trade-off of hole H-19.
///
/// The layout tables live in the storage of the contract on top, so that it keeps control of its storage layout. This
/// contract reaches them through one hook, `_layoutTables`. The three tables share one row type, `SlotRange`.
///
/// Split for the gas cap. The execution layer checks of a delivery (receipt, transaction, log) are in the external
/// library `ReceiptProofLib`, the account and storage proofs of the opening in `OpeningProofLib`, and the anchor, the
/// ancestry, the fork proof, the block hash branch and the layout rules in `BeaconLayoutLib`, so that the creation of the
/// contract on top and of each library stays under the per-transaction gas cap of EIP-7825 (16,777,216). Both are linked: no owner, no storage of their own, their addresses fixed in the
/// bytecode. The layout library runs in the storage of the contract on top, with the tables passed as `storage`
/// arguments. The errors and the events stay declared here, and the libraries use them, so nothing changes outside.
abstract contract BeaconProofVerifier {
/// @notice One row of a layout table: a validated position and the slots at which it was validated. The three tables
/// share this one type (`LayoutTables`), so the range rule and the lookups are one code for all three.
/// @param gindex The validated generalized index: of `BeaconState.block_roots` (table `states`), of
/// `BeaconBlockBody.execution_payload.block_hash` (table `bodies`), or of `BeaconState.historical_summaries` (table
/// `historicals`).
/// @param firstSlot The lowest slot at which the position was validated: a state slot, or a header slot for `bodies`.
/// @param lastSlot The highest slot at which the position was validated.
struct SlotRange {
uint256 gindex;
uint64 firstSlot;
uint64 lastSlot;
}
/// @notice Evidence for a `block_roots` position: two stored earlier headers under one stored later state.
/// @param laterHeader A stored header. Its `stateRoot` holds the block roots.
/// @param earlierSlotA A stored slot before and within 8192 slots of the later header.
/// @param earlierSlotB Another such slot.
/// @param branchA The branch from the stored root at `earlierSlotA` to the later state root.
/// @param branchB The branch from the stored root at `earlierSlotB` to the later state root.
struct BlockRootsEvidence {
BeaconBlockHeader laterHeader;
uint64 earlierSlotA;
uint64 earlierSlotB;
bytes32[] branchA;
bytes32[] branchB;
}
/// @notice The three layout tables of the contract on top, in one storage variable, so that one storage argument
/// reaches all three in `BeaconLayoutLib`. Three dynamic arrays take three consecutive slots, the same slots as three
/// array variables declared in this order.
/// @param states The validated `block_roots` positions, by state slot.
/// @param bodies The validated block hash positions, by header slot.
/// @param historicals The validated `historical_summaries` positions, by state slot.
struct LayoutTables {
SlotRange[] states;
SlotRange[] bodies;
SlotRange[] historicals;
}
/// @notice A proof of the fork of one beacon state: `fork.current_version` and `genesis_validators_root` under the same
/// state root. `ForkShape.judge` reads it and returns the shape of the state tree. The version is not judged by name.
/// @param version The claimed `fork.current_version` of the state.
/// @param versionBranch The branch of the version leaf, deepest first: `Fork.previous_version`, the node over
/// `Fork.epoch`, then the state levels. 7 entries for plain depth 5 and for the progressive state, 8 for depth 6, 9 for
/// depth 7.
/// @param genesisValidatorsRootBranch The branch of `genesis_validators_root` (state field 1), deepest first: as many
/// entries as the plain depth, or 5 for the progressive state. Its leaf is `lightClient.genesisValidatorsRoot()`.
struct ForkProof {
bytes4 version;
bytes32[] versionBranch;
bytes32[] genesisValidatorsRootBranch;
}
/// @notice Evidence for a block hash position: a stored header whose body holds its stored execution block hash.
/// @param header A stored header.
/// @param branch The branch from the stored execution block hash to the body root of the header.
/// @param fork The fork proof of the state of `header`. It must prove a plain shape: the body of a header whose state is
/// progressive (Gloas on) holds no payload.
struct BlockHashEvidence {
BeaconBlockHeader header;
bytes32[] branch;
ForkProof fork;
}
/// @notice Evidence for a `historical_summaries` position: a stored header in a completed era, proven at the claimed
/// position under a later stored anchor's state root.
/// @param anchorHeader A stored header. Its `stateRoot` holds `historical_summaries`.
/// @param earlierSlot A stored slot more than 8192 slots below the anchor, in an era at or after `capellaEra`.
/// @param branch The branch from the stored root at `earlierSlot` to the anchor state root. Its length is exact.
struct HistoricalSummariesEvidence {
BeaconBlockHeader anchorHeader;
uint64 earlierSlot;
bytes32[] branch;
}
/// @notice The evidence for `openDeposits`: a block of the remote chain whose hash the light client stored, and the
/// storage of the remote light client under the state root of that block.
/// @param remoteSlot A slot at which the light client of this vault stored an execution block hash.
/// @param remoteHeaderRlp The RLP of the execution block header whose hash is stored at `remoteSlot`.
/// @param accountProof The state trie proof of the account of `remoteLightClient`.
/// @param storedSlot A slot whose `executionBlockHashes` entry in the remote light client is not zero.
/// @param storageProof The storage trie proof of that entry.
struct OpeningProof {
uint64 remoteSlot;
bytes remoteHeaderRlp;
bytes[] accountProof;
uint64 storedSlot;
bytes[] storageProof;
}
/// @notice The length of `state.block_roots`. A deposit block at most this far below its anchor uses the recent path.
uint64 public constant SLOTS_PER_HISTORICAL_ROOT = ERA_SLOTS;
/// @notice `log2(SLOTS_PER_HISTORICAL_ROOT)`: the depth of the `block_roots` vector.
uint256 public constant BLOCK_ROOTS_VECTOR_DEPTH = ERA_DEPTH;
/// @notice `log2(HISTORICAL_ROOTS_LIMIT)` with `HISTORICAL_ROOTS_LIMIT = 2**24`: the depth of the
/// `historical_summaries` list below its data node.
uint256 public constant HISTORICAL_SUMMARIES_LIST_DEPTH = HISTORICAL_LIST_DEPTH;
// The position rules, the fork positions and the depths are constants of `BeaconLayoutLib`; the execution header and
// account field indices are constants of `ReceiptProofLib` and `OpeningProofLib`. One copy of each, in the code that
// reads it.
/// @notice A constructor argument is zero.
error ZeroValue(string name);
/// @notice The remote chain is the local chain.
error RemoteChainIsLocalChain();
/// @notice Deposits are closed until `openDeposits` proves that the other chain can pay them.
error DepositsNotOpen();
/// @notice The light client of this vault stored no execution block hash at the slot of the opening proof.
error OpeningSlotNotStored(uint64 slot);
/// @notice The header in the opening proof does not hash to the stored execution block hash.
error OpeningHeaderMismatch(bytes32 expected, bytes32 actual);
/// @notice The header, the account or the storage entry of the opening proof does not decode to the expected fields.
error OpeningProofMalformed();
/// @notice The proven entry of the remote light client is empty.
error OpeningEntryEmpty(uint64 storedSlot);
/// @notice The anchor header is not the finalized header stored for its slot.
error AnchorNotStored(uint64 slot, bytes32 anchorRoot);
/// @notice The deposit block is not strictly before the anchor.
error DepositNotBeforeAnchor(uint64 depositSlot, uint64 anchorSlot);
/// @notice The deposit era is before `capellaEra`, so no historical summary covers it.
error DepositBeforeCapellaEra(uint64 depositEra, uint64 capellaEra);
/// @notice The era index does not fit in the summaries list (2**24 entries). It would spill into a neighbour.
error HistoricalIndexOutOfRange(uint64 index);
/// @notice A `historical_summaries` evidence slot is not more than 8192 slots below its anchor.
error EvidenceSlotNotHistorical(uint64 earlierSlot, uint64 anchorSlot);
/// @notice `addBlockHashLayout` was given a header whose state the fork proof shows to be progressive (Gloas on). The
/// stored hash of such a slot is `latest_block_hash`, not the payload of the block of that slot, and the body holds
/// only a bid. A message source of that shape takes no layout: it reads the fixed bid index.
error GloasSlotRefused(uint64 slot);
/// @notice The fork proof proves no allowed shape under the state root. `verdict` is the `ForkShape.Verdict`: 1 no
/// valid version branch, 2 no valid genesis validators root branch, 3 a version branch length of no allowed shape.
error ForkShapeProofInvalid(uint8 verdict);
/// @notice The slot lies inside the validated range of another position, so a layout cannot be validated there.
error LayoutRangeConflict(uint64 slot);
/// @notice No validated layout covers the slot. Anyone can add one with evidence.
error LayoutNotValidated(uint64 slot);
/// @notice A candidate position is zero or deeper than the bound.
error LayoutOutOfBounds(uint256 gindex);
/// @notice A layout evidence slot holds no stored header.
error EvidenceSlotNotStored(uint64 slot);
/// @notice The two earlier slots of the evidence are the same slot.
error EvidenceSlotsEqual(uint64 slot);
/// @notice An earlier slot is not before the later header, or lies more than 8192 slots below it.
error EvidenceSlotOutOfWindow(uint64 earlierSlot, uint64 laterSlot);
/// @notice The evidence does not prove the candidate position.
error LayoutEvidenceInvalid();
/// @notice The ancestry branch does not lead from the deposit header to the anchor state.
error AncestryBranchInvalid();
/// @notice The block hash branch does not lead from the execution block hash to the deposit header body.
error BlockHashBranchInvalid();
/// @notice The execution header does not decode to a header with a receipts root.
error MalformedExecutionHeader();
/// @notice The receipt has an unsupported type byte or does not decode.
error MalformedReceipt();
/// @notice The receipt records a failed transaction.
error ReceiptFailed();
/// @notice The log index is past the end of the receipt's logs.
error LogIndexOutOfRange(uint256 logIndex, uint256 logCount);
/// @notice A candidate position is not the position of the named field in any accepted tree shape.
error LayoutPositionInvalid(uint256 gindex);
/// @notice The log was not emitted by the remote vault.
error WrongEmitter(address expected, address actual);
/// @notice The log is not a `DepositInitiated` log.
error WrongEventTopic(bytes32 actual);
/// @notice The log has the deposit topic but not the deposit layout.
error MalformedLog();
/// @notice Emitted when a validated `block_roots` position is added or its validated range grows.
event BlockRootsLayoutValidated(uint256 indexed blockRootsGindex, uint64 firstSlot, uint64 lastSlot);
/// @notice Emitted when a validated block hash position is added or its validated range grows.
event BlockHashLayoutValidated(uint256 indexed blockHashGindex, uint64 firstSlot, uint64 lastSlot);
/// @notice Emitted when a validated `historical_summaries` position is added or its validated range grows.
event HistoricalSummariesLayoutValidated(
uint256 indexed historicalSummariesGindex, uint64 firstSlot, uint64 lastSlot
);
/// @notice Emitted once, when `openDeposits` proves the condition. Deposits stay open from then on.
/// @param remoteSlot The slot at which the light client of this vault stored the proven block of the remote chain.
/// @param remoteBlockHash The hash of that block.
/// @param storedSlot The slot whose execution block hash the remote light client had stored in that block.
event DepositsOpened(uint64 indexed remoteSlot, bytes32 indexed remoteBlockHash, uint64 storedSlot);
/// @notice The light client that tracks the finalized chain of the remote chain.
IBeaconLightClient public immutable lightClient;
/// @notice `floor(capellaForkSlot / 8192)` of the remote chain: the era of the first `historical_summaries` entry.
/// Ethereum 758 (Capella slot 6209536), PulseChain 0 (Capella epoch 3, slot 96). Zero is valid.
uint64 public immutable capellaEra;
/// @notice The light client on the other chain. It tracks the beacon chain of this chain and feeds the remote contract.
address public immutable remoteLightClient;
// Gloas. From the Gloas fork of the remote chain on, `lightClient.executionBlockHashes(slot)` holds
// `state.latest_block_hash` of the finalized state: the newest payload that a block confirmed BEFORE the slot, not the
// payload of the slot, and the body of a Gloas block holds a bid and no payload. So `addBlockHashLayout` refuses a
// header whose state is proven progressive, and a message source of that shape reads the bid `parent_block_hash` of a
// LATER block (`BeaconLayoutLib.GLOAS_BID_PARENT_BLOCK_HASH_GINDEX`). A Gloas head is used through the opening proof,
// which checks an execution header RLP against the stored hash. No slot of the fork is configured: the fork proof of
// each header decides (see the notes of the contract).
/// @param lightClient_ The light client of the remote chain.
/// @param capellaEra_ `floor(capellaForkSlot / 8192)` of the remote chain. The deploy script checks it.
/// @param remoteLightClient_ The light client on the other chain. `openDeposits` reads its storage.
/// @dev The constructor only stores. The contract on top checks the values, in the order of its own arguments.
constructor(address lightClient_, uint64 capellaEra_, address remoteLightClient_) {
lightClient = IBeaconLightClient(lightClient_);
capellaEra = capellaEra_;
remoteLightClient = remoteLightClient_;
}
// ------------------------------------------------------------------ storage hook
/// @dev The three layout tables. The contract on top declares one `LayoutTables` variable, so it keeps control of its
/// storage layout.
function _layoutTables() internal view virtual returns (LayoutTables storage);
// ------------------------------------------------------------------ opening proof
/// @dev Checks the opening proof and returns the block hash that it proved. The contract on top sets its own flag and
/// emits `DepositsOpened`. The proof walks four links. 1: its light client stored the execution block hash of a
/// block of the other chain at `remoteSlot`. 2: the header in the proof hashes to that block hash, and it holds a
/// state root. 3: under that state root, the account of `remoteLightClient` holds a storage root. 4: under that
/// storage root, `executionBlockHashes[storedSlot]` is not zero. Only `update` writes that entry, so one update was
/// stored, at a head that the other beacon chain had already finalized. That block is final on the other chain and
/// final in the light client of this contract, so no reorganization undoes it. A message sent now lies after that
/// head, because a head is never later than the clock of the chain that stored it. Links 2 to 4 are in
/// `OpeningProofLib.requireOpeningEntry`.
function _verifyOpening(OpeningProof calldata proof) internal view returns (bytes32 blockHash) {
blockHash = lightClient.executionBlockHashes(proof.remoteSlot);
if (blockHash == bytes32(0)) revert OpeningSlotNotStored(proof.remoteSlot);
bytes32 actual = keccak256(proof.remoteHeaderRlp);
if (actual != blockHash) revert OpeningHeaderMismatch(blockHash, actual);
OpeningProofLib.requireOpeningEntry(
proof.remoteHeaderRlp, proof.accountProof, proof.storedSlot, proof.storageProof, remoteLightClient
);
}
// ------------------------------------------------------------------ proof checks
/// @dev Checks 1 to 3: the anchor is a stored header and the source block is its ancestor. The rules run in
/// `BeaconLayoutLib.requireAncestry`, over the layout tables of this contract.
/// @param anchorHeader A header that the light client stored.
/// @param sourceHeader The beacon block that carries the proven execution block.
/// @param branch The branch from the root of `sourceHeader` to the state root of the anchor.
function _requireAncestry(
BeaconBlockHeader calldata anchorHeader,
BeaconBlockHeader calldata sourceHeader,
bytes32[] calldata branch
) internal view {
BeaconLayoutLib.requireAncestry(_layoutTables(), lightClient, capellaEra, anchorHeader, sourceHeader, branch);
}
/// @dev Check 4. The fork proof of the source state picks the rule, then the execution block hash must sit in the body
/// of the source header. A plain shape (before Gloas) takes the validated payload block hash position. The progressive
/// shape (Gloas on) takes the bid `parent_block_hash` at the fixed index 2856 (see
/// `BeaconLayoutLib.GLOAS_BID_PARENT_BLOCK_HASH_GINDEX`). The rule runs in `BeaconLayoutLib.requireBlockHash`.
/// @param blockHash The execution block hash to prove.
/// @param sourceHeader The beacon block that carries the proven execution block. Check 3 proved it.
/// @param branch The branch from `blockHash` to the body root of `sourceHeader`.
/// @param sourceFork The fork proof of the state of `sourceHeader`.
function _requireBlockHashBranch(
bytes32 blockHash,
BeaconBlockHeader calldata sourceHeader,
bytes32[] calldata branch,
ForkProof calldata sourceFork
) internal view {
BeaconLayoutLib.requireBlockHash(_layoutTables().bodies, lightClient, blockHash, sourceHeader, branch, sourceFork);
}
/// @notice Adds a `block_roots` position, or widens its validated range, given evidence from stored data.
/// @dev Open to anyone. The position must be the `block_roots` field itself: `2**d + 5` with `d` a plain shape of
/// `ForkShape.allowedShapes` (5 to 7), or 352 while the progressive shape is allowed (Gloas). Any other position
/// reverts with `LayoutPositionInvalid`, even when the evidence would match (for example the position of
/// `eth1_data_votes`, whose entries a proposer writes). The position is accepted only when, under the stored later
/// state root, the leaf at
/// `blockRootsGindex * 8192 + slot % 8192` equals the light client's stored header root, for two different
/// stored earlier slots. A wrong position cannot match. The position is then usable for the later header's slot.
/// The rules run in `BeaconLayoutLib.addBlockRootsLayout`.
/// @param blockRootsGindex The candidate generalized index of `BeaconState.block_roots`.
/// @param evidence Two stored earlier headers under one stored later state.
function addBlockRootsLayout(uint256 blockRootsGindex, BlockRootsEvidence calldata evidence) external {
BeaconLayoutLib.addBlockRootsLayout(_layoutTables().states, lightClient, blockRootsGindex, evidence);
}
/// @notice Adds a block hash position, or widens its validated range, given evidence from stored data.
/// @dev Open to anyone. The position must be the block hash field itself: `(2**db + 9) * 2**dp + 12` with `db` and
/// `dp` in 4 to 5, which is 412, 668, 812 or 1324. Any other position reverts with `LayoutPositionInvalid`, even when
/// the evidence would match (for example `graffiti` at 18, or `eth1_data.block_hash` at 70, which a proposer can
/// fill with a copy of the block hash). The position is accepted only when, under the body root of a stored header, the leaf at
/// `blockHashGindex` equals the light client's stored execution block hash of that header. The fork proof of the state
/// of the header must prove a plain shape. A header whose state is progressive (Gloas on) is refused with
/// `GloasSlotRefused`: in a Gloas body, 668 and 1324 lie under `graffiti`, where a proposer could place the stored hash.
/// The rules run in `BeaconLayoutLib.addBlockHashLayout`.
/// @param blockHashGindex The candidate generalized index of `BeaconBlockBody.execution_payload.block_hash`.
/// @param evidence A stored header, the branch to its body root, and the fork proof of its state.
function addBlockHashLayout(uint256 blockHashGindex, BlockHashEvidence calldata evidence) external {
BeaconLayoutLib.addBlockHashLayout(_layoutTables().bodies, lightClient, blockHashGindex, evidence);
}
/// @notice Adds a `historical_summaries` position, or widens its validated range, given evidence from stored data.
/// @dev Open to anyone. The position is accepted only when, under the stored anchor state root, the leaf at the
/// historical index of the candidate equals the light client's stored header root at `earlierSlot`. The index is
/// built as `withdraw` builds it, so the candidate must also fit the era formula. A candidate that is another
/// state field (`block_roots`, `finalized_checkpoint.root`, `latest_block_header`) or a list of another depth
/// cannot match. The position is then usable for the anchor's slot. The rules run in
/// `BeaconLayoutLib.addHistoricalSummariesLayout`.
/// @param historicalSummariesGindex The candidate generalized index of `BeaconState.historical_summaries`.
/// @param evidence A stored anchor, a stored earlier slot in a completed era, and the branch between them.
function addHistoricalSummariesLayout(
uint256 historicalSummariesGindex,
HistoricalSummariesEvidence calldata evidence
) external {
BeaconLayoutLib.addHistoricalSummariesLayout(
_layoutTables().historicals, lightClient, capellaEra, historicalSummariesGindex, evidence
);
}
/// @notice The validated `block_roots` positions and their slot ranges.
function stateLayouts() external view returns (SlotRange[] memory) {
return _layoutTables().states;
}
/// @notice The validated `historical_summaries` positions and their slot ranges.
function historicalLayouts() external view returns (SlotRange[] memory) {
return _layoutTables().historicals;
}
/// @notice The validated block hash positions and their slot ranges.
function bodyLayouts() external view returns (SlotRange[] memory) {
return _layoutTables().bodies;
}
}
src/hardened/vendor/optimism/rlp/RLPErrors.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice The length of an RLP item must be greater than zero to be decodable
error EmptyItem();
/// @notice The decoded item type for list is not a list item
error UnexpectedString();
/// @notice The RLP item has an invalid data remainder
error InvalidDataRemainder();
/// @notice Decoded item type for bytes is not a string item
error UnexpectedList();
/// @notice The length of the content must be greater than the RLP item length
error ContentLengthMismatch();
/// @notice Invalid RLP header for RLP item
error InvalidHeader();
src/hardened/ReceiptLogs.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {RLPReader} from "./vendor/optimism/rlp/RLPReader.sol";
import {
EmptyItem,
UnexpectedString,
InvalidDataRemainder,
ContentLengthMismatch,
InvalidHeader
} from "./vendor/optimism/rlp/RLPErrors.sol";
/// @title ReceiptLogs
/// @notice Finds one item of an RLP list without a fixed limit on the number of items.
/// @dev The vendored `RLPReader.readList` copies at most 32 items and panics on the 33rd. A receipt can hold many more
/// logs, so a deposit in such a transaction could never be withdrawn. This library steps over the items one by one and
/// returns only the item that the caller asks for. The vendored decoder keeps its length helper private, so this library
/// holds its own header decoder. It applies the same rules as the vendored one: a canonical header, no leading zero in a
/// long length, no long form for a short length, and every item inside the bytes that remain. It returns the vendored
/// `RLPItem` type, so the caller decodes the chosen item with the vendored `readList` and `readBytes`.
library ReceiptLogs {
/// @notice Finds the item at `index` of an RLP list.
/// @dev When the index is past the end, the walk reaches the end of the list and `count` holds the number of items.
/// When the item is found, the walk stops there and `count` is zero: the caller must not read it.
/// @param list The RLP list item. It must be a list that fills the whole item.
/// @param index The position of the wanted item.
/// @return found Whether the list holds an item at `index`.
/// @return item The wanted item, with its header. Empty when `found` is false.
/// @return count The number of items in the list when `found` is false.
function itemAt(RLPReader.RLPItem memory list, uint256 index)
internal
pure
returns (bool found, RLPReader.RLPItem memory item, uint256 count)
{
(uint256 listOffset, uint256 listLength, bool isList) = _header(list.ptr, list.length);
if (!isList) revert UnexpectedString();
if (listOffset + listLength != list.length) revert InvalidDataRemainder();
uint256 base = RLPReader.MemoryPointer.unwrap(list.ptr);
uint256 offset = listOffset;
while (offset < list.length) {
RLPReader.MemoryPointer itemPointer = RLPReader.MemoryPointer.wrap(base + offset);
(uint256 itemOffset, uint256 itemLength,) = _header(itemPointer, list.length - offset);
if (count == index) {
return (true, RLPReader.RLPItem({length: itemOffset + itemLength, ptr: itemPointer}), 0);
}
count += 1;
offset += itemOffset + itemLength;
}
return (false, RLPReader.RLPItem({length: 0, ptr: RLPReader.MemoryPointer.wrap(0)}), count);
}
/// @dev Decodes the header of the item at `pointer`, which has `available` bytes left. Returns the header length,
/// the payload length and whether the item is a list. It reverts on every non-canonical or truncated header.
function _header(RLPReader.MemoryPointer pointer, uint256 available)
private
pure
returns (uint256 headerLength, uint256 payloadLength, bool isList)
{
if (available == 0) revert EmptyItem();
uint256 position = RLPReader.MemoryPointer.unwrap(pointer);
uint256 prefix;
uint256 word;
assembly {
word := mload(add(position, 1))
prefix := byte(0, mload(position))
}
if (prefix <= 0x7f) return (0, 1, false);
if (prefix <= 0xb7) return _shortHeader(prefix - 0x80, word, available, false);
if (prefix <= 0xbf) return _longHeader(prefix - 0xb7, word, available, false);
if (prefix <= 0xf7) return _shortHeader(prefix - 0xc0, word, available, true);
return _longHeader(prefix - 0xf7, word, available, true);
}
/// @dev A header whose payload length is in the prefix byte (at most 55).
function _shortHeader(uint256 length, uint256 word, uint256 available, bool isList)
private
pure
returns (uint256, uint256, bool)
{
if (available <= length) revert ContentLengthMismatch();
// A single byte below 0x80 must be written as itself, never behind a prefix.
if (!isList && length == 1 && (word >> 248) < 0x80) revert InvalidHeader();
return (1, length, isList);
}
/// @dev A header whose payload length follows the prefix byte in `lengthOfLength` bytes.
function _longHeader(uint256 lengthOfLength, uint256 word, uint256 available, bool isList)
private
pure
returns (uint256, uint256, bool)
{
if (available <= lengthOfLength) revert ContentLengthMismatch();
if ((word >> 248) == 0) revert InvalidHeader();
uint256 length = word >> (256 - 8 * lengthOfLength);
if (length <= 55) revert InvalidHeader();
if (available <= lengthOfLength + length) revert ContentLengthMismatch();
return (1 + lengthOfLength, length, isList);
}
}
src/hardened/AmbMessageCodec.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @title AmbMessageCodec
/// @notice The Arbitrary Message Bridge message encoding, byte for byte as OmniBridge has it.
/// @dev Sources, read on 2026-10-24 at commit 908a48107919d4ab127f9af07d44d47eac91547e of
/// `poanetwork/tokenbridge-contracts`:
/// - `contracts/upgradeable_contracts/arbitrary_message/MessageDelivery.sol`: `_packHeader` writes the message, and
/// `_getNewMessageId` builds the message identifier.
/// - `contracts/libraries/ArbitraryMessage.sol`: `unpackData` reads it, and its comment lists the offsets.
/// - `contracts/upgradeable_contracts/arbitrary_message/VersionableAMB.sol`: `MESSAGE_PACKING_VERSION`.
/// - `contracts/upgradeable_contracts/arbitrary_message/BasicAMB.sol`: `_setChainIds` fixes the chain identifier
/// lengths (the fewest bytes that hold the value, so leading zero bytes are not kept).
///
/// The layout, with offsets in bytes:
///
/// 0 : 32 bytes message identifier
/// 32 : 20 bytes sender
/// 52 : 20 bytes executor (the target)
/// 72 : 4 bytes gas limit (uint32)
/// 76 : 1 byte length X of the source chain identifier
/// 77 : 1 byte length Y of the destination chain identifier
/// 78 : 1 byte data type (0x00 for `requireToPassMessage`, 0x80 for `requireToConfirmMessage`)
/// 79 : X bytes source chain identifier
/// 79 + X : Y bytes destination chain identifier
/// 79 + X + Y : the rest, the call data
///
/// The message identifier is `MESSAGE_PACKING_VERSION | (keccak256(chainId, bridge) & BRIDGE_ID_MASK) | nonce`, where
/// `chainId` is the 32 byte source chain identifier, `bridge` is the 20 byte address of the sending bridge, and the
/// nonce takes the lowest 8 bytes. The bytes 4 to 23 of the hash are kept. The nonce only makes identifiers unique.
library AmbMessageCodec {
/// @notice The message is shorter than its header says, or a chain identifier length is not 1 to 32.
error MalformedMessage();
/// @notice The message format version. It stands in the top 4 bytes of every message identifier.
bytes32 internal constant MESSAGE_PACKING_VERSION = bytes32(uint256(0x00050000) << 224);
/// @notice The bytes of the hash of (chain identifier, bridge) that stand in the message identifier.
bytes32 internal constant BRIDGE_ID_MASK = 0x00000000ffffffffffffffffffffffffffffffffffffffff0000000000000000;
/// @notice The data type of a message sent with `requireToPassMessage`.
uint8 internal constant DATA_TYPE_PASS = 0x00;
/// @notice The data type of a message sent with `requireToConfirmMessage`.
uint8 internal constant DATA_TYPE_CONFIRM = 0x80;
/// @dev The fixed part of the header: 32 + 20 + 20 + 4 + 1 + 1 + 1 bytes.
uint256 private constant FIXED_HEADER_LENGTH = 79;
/// @notice The fields of a message, without the call data.
struct Header {
bytes32 messageId;
address sender;
address executor;
uint32 gasLimit;
uint8 dataType;
uint256 sourceChainId;
uint256 destinationChainId;
}
/// @notice The bytes of a message identifier that no bridge writes and a receiver checks: the version.
/// @param messageId The identifier.
function hasValidVersion(bytes32 messageId) internal pure returns (bool) {
return messageId & 0xffffffff00000000000000000000000000000000000000000000000000000000 == MESSAGE_PACKING_VERSION;
}
/// @notice The identifier prefix of a bridge: the version and the bridge part. Add the nonce to get an identifier.
/// @param sourceChainId The chain identifier of the sending bridge.
/// @param bridge The address of the sending bridge.
function messageIdPrefix(uint256 sourceChainId, address bridge) internal pure returns (bytes32) {
return MESSAGE_PACKING_VERSION | (keccak256(abi.encodePacked(sourceChainId, bridge)) & BRIDGE_ID_MASK);
}
/// @notice Writes a message.
/// @param header The fields. `gasLimit` and the chain identifiers are written as the format says.
/// @param data The call data.
function encode(Header memory header, bytes calldata data) internal pure returns (bytes memory) {
uint256 sourceLength = chainIdLength(header.sourceChainId);
uint256 destinationLength = chainIdLength(header.destinationChainId);
return abi.encodePacked(
header.messageId,
header.sender,
header.executor,
header.gasLimit,
uint8(sourceLength),
uint8(destinationLength),
header.dataType,
_chainIdBytes(header.sourceChainId, sourceLength),
_chainIdBytes(header.destinationChainId, destinationLength),
data
);
}
/// @notice Reads a message.
/// @param encoded The message, as `encode` writes it.
/// @return header The fields.
/// @return data The call data. It is a copy.
function decode(bytes memory encoded) internal view returns (Header memory header, bytes memory data) {
if (encoded.length < FIXED_HEADER_LENGTH) revert MalformedMessage();
uint256 sourceLength;
uint256 destinationLength;
assembly {
mstore(header, mload(add(encoded, 32)))
mstore(add(header, 32), shr(96, mload(add(encoded, 64))))
mstore(add(header, 64), shr(96, mload(add(encoded, 84))))
mstore(add(header, 96), shr(224, mload(add(encoded, 104))))
sourceLength := byte(0, mload(add(encoded, 108)))
destinationLength := byte(0, mload(add(encoded, 109)))
mstore(add(header, 128), byte(0, mload(add(encoded, 110))))
}
if (sourceLength == 0 || sourceLength > 32 || destinationLength == 0 || destinationLength > 32) {
revert MalformedMessage();
}
uint256 dataStart = FIXED_HEADER_LENGTH + sourceLength + destinationLength;
if (encoded.length < dataStart) revert MalformedMessage();
uint256 destinationStart = FIXED_HEADER_LENGTH + sourceLength;
assembly {
mstore(
add(header, 160),
shr(sub(256, shl(3, sourceLength)), mload(add(encoded, add(32, FIXED_HEADER_LENGTH))))
)
mstore(
add(header, 192),
shr(sub(256, shl(3, destinationLength)), mload(add(encoded, add(32, destinationStart))))
)
}
data = _copy(encoded, dataStart);
}
/// @notice The fewest bytes that hold a chain identifier: 1 to 32 (an identifier of zero takes one byte).
/// @param chainId The chain identifier.
function chainIdLength(uint256 chainId) internal pure returns (uint256 length) {
length = 1;
while (length < 32 && chainId >> (8 * length) != 0) {
length++;
}
}
/// @dev The low `length` bytes of `chainId`, most significant first.
function _chainIdBytes(uint256 chainId, uint256 length) private pure returns (bytes memory encoded) {
encoded = new bytes(length);
for (uint256 i = 0; i < length; i++) {
encoded[length - 1 - i] = bytes1(uint8(chainId >> (8 * i)));
}
}
/// @dev The bytes of `source` from `start` to its end, in new memory. The copy goes through the identity precompile.
function _copy(bytes memory source, uint256 start) private view returns (bytes memory copy) {
uint256 length = source.length - start;
copy = new bytes(length);
bool ok;
assembly {
ok := staticcall(gas(), 4, add(add(source, 32), start), length, add(copy, 32), length)
}
if (!ok) revert MalformedMessage();
}
}
src/hardened/SSZ.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @notice A beacon block header, as in the consensus specification.
struct BeaconBlockHeader {
uint64 slot;
uint64 proposerIndex;
bytes32 parentRoot;
bytes32 stateRoot;
bytes32 bodyRoot;
}
/// @title SSZ
/// @notice The small part of SimpleSerialize that the bridge needs: the hash tree root of a
/// `BeaconBlockHeader`, and the check of a Merkle branch by generalized index.
/// @dev Every hash is SHA-256 through the precompile at address 0x02, which exists on Ethereum and PulseChain.
/// The compiler emits a call to that precompile for `sha256`.
library SSZ {
/// @notice The branch length differs from the depth of the generalized index.
error BranchLengthMismatch(uint256 expected, uint256 actual);
/// @notice The generalized index is zero.
error ZeroGeneralizedIndex();
/// @notice The hash tree root of a beacon block header: five leaves padded to eight.
/// @param header The header.
function hashTreeRoot(BeaconBlockHeader calldata header) internal pure returns (bytes32) {
bytes32 left = _hashPair(
_hashPair(_uint64Leaf(header.slot), _uint64Leaf(header.proposerIndex)),
_hashPair(header.parentRoot, header.stateRoot)
);
bytes32 right = _hashPair(_hashPair(header.bodyRoot, bytes32(0)), _hashPair(bytes32(0), bytes32(0)));
return _hashPair(left, right);
}
/// @notice The hash tree root of a header held in memory.
/// @param header The header.
function hashTreeRootMemory(BeaconBlockHeader memory header) internal pure returns (bytes32) {
bytes32 left = _hashPair(
_hashPair(_uint64Leaf(header.slot), _uint64Leaf(header.proposerIndex)),
_hashPair(header.parentRoot, header.stateRoot)
);
bytes32 right = _hashPair(_hashPair(header.bodyRoot, bytes32(0)), _hashPair(bytes32(0), bytes32(0)));
return _hashPair(left, right);
}
/// @notice Checks that `leaf` sits at `generalizedIndex` under `root`, given the sibling hashes from leaf to root.
/// @dev The branch length must equal the depth of the index, which fixes the tree shape. A branch of another
/// length is an error, not a failed check, so a wrong fork row shows up as a clear revert.
/// @param leaf The leaf value.
/// @param branch The siblings, deepest first.
/// @param generalizedIndex The generalized index of the leaf.
/// @param root The expected root.
function isValidBranch(bytes32 leaf, bytes32[] calldata branch, uint256 generalizedIndex, bytes32 root)
internal
pure
returns (bool)
{
uint256 depth = depthOf(generalizedIndex);
if (branch.length != depth) revert BranchLengthMismatch(depth, branch.length);
bytes32 value = leaf;
for (uint256 level = 0; level < depth; level++) {
bool nodeIsRight = (generalizedIndex >> level) & 1 == 1;
value = nodeIsRight ? _hashPair(branch[level], value) : _hashPair(value, branch[level]);
}
return value == root;
}
/// @notice The same check for a branch held in memory, for evidence that the caller decoded from `bytes`.
/// @param leaf The leaf value.
/// @param branch The siblings, deepest first.
/// @param generalizedIndex The generalized index of the leaf.
/// @param root The expected root.
function isValidBranchMemory(bytes32 leaf, bytes32[] memory branch, uint256 generalizedIndex, bytes32 root)
internal
pure
returns (bool)
{
uint256 depth = depthOf(generalizedIndex);
if (branch.length != depth) revert BranchLengthMismatch(depth, branch.length);
bytes32 value = leaf;
for (uint256 level = 0; level < depth; level++) {
bool nodeIsRight = (generalizedIndex >> level) & 1 == 1;
value = nodeIsRight ? _hashPair(branch[level], value) : _hashPair(value, branch[level]);
}
return value == root;
}
/// @notice The depth of a generalized index: the number of bits below the leading one.
/// @param generalizedIndex The index. It must not be zero.
function depthOf(uint256 generalizedIndex) internal pure returns (uint256 depth) {
if (generalizedIndex == 0) revert ZeroGeneralizedIndex();
while (generalizedIndex > 1) {
generalizedIndex >>= 1;
depth++;
}
}
/// @dev A uint64 leaf is the little-endian bytes of the value, padded on the right with zeros.
function _uint64Leaf(uint64 value) private pure returns (bytes32) {
uint64 swapped = ((value & 0xFF00FF00FF00FF00) >> 8) | ((value & 0x00FF00FF00FF00FF) << 8);
swapped = ((swapped & 0xFFFF0000FFFF0000) >> 16) | ((swapped & 0x0000FFFF0000FFFF) << 16);
swapped = (swapped >> 32) | (swapped << 32);
return bytes32(uint256(swapped) << 192);
}
function _hashPair(bytes32 left, bytes32 right) private pure returns (bytes32) {
return sha256(abi.encodePacked(left, right));
}
}
src/hardened/BeaconLayoutLib.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {IBeaconLightClient} from "./IBeaconLightClient.sol";
import {BeaconBlockHeader, SSZ} from "./SSZ.sol";
import {BeaconProofVerifier} from "./BeaconProofVerifier.sol";
import {ForkShape} from "./ForkShape.sol";
/// @dev The era constants, one copy for this library and the public constants of `BeaconProofVerifier`:
/// `SLOTS_PER_HISTORICAL_ROOT`, its log2, and the log2 of `HISTORICAL_ROOTS_LIMIT` (2**24).
uint64 constant ERA_SLOTS = 8192;
uint256 constant ERA_DEPTH = 13;
uint256 constant HISTORICAL_LIST_DEPTH = 24;
/// @title BeaconLayoutLib
/// @notice The fork layout tables of the message bridge: the position rules and the evidence checks of
/// `addBlockRootsLayout`, `addBlockHashLayout` and `addHistoricalSummariesLayout`, the range rule, and the lookups that
/// turn a slot into the validated position of its fork. The rules are documented on `BeaconProofVerifier`.
/// @dev An external library, linked into `MessageBridge`, so that each contract creation of the bridge stays under the
/// per-transaction gas cap of EIP-7825 (16,777,216). It runs with DELEGATECALL in the storage of the bridge: the tables
/// are `storage` arguments that the bridge passes, so they stay in the storage layout of the bridge. It has no owner and
/// no storage of its own, and its address is fixed in the bytecode of the bridge, so the bridge stays immutable. It reverts
/// with the errors of `BeaconProofVerifier` and emits its events, so the bridge looks the same from outside.
library BeaconLayoutLib {
/// @dev The deepest accepted `block_roots` or `historical_summaries` position (the state container only), apart from
/// the fixed Gloas position of `historical_summaries`.
uint256 private constant MAX_BLOCK_ROOTS_DEPTH = 8;
/// @dev The position of `BeaconState.block_roots` in the progressive Gloas state: field 5 is chunk 5, the first leaf of
/// the 16 leaf subtree at node 22, which starts at 352 (`specs/gloas/light-client/sync-protocol.md` fixes the rules,
/// and `lc-core` derives the number from the field list).
uint256 private constant GLOAS_BLOCK_ROOTS_GINDEX = 352;
/// @dev The position of `signed_execution_payload_bid.message.parent_block_hash` in the progressive Gloas
/// `BeaconBlockBody`: field 10 of the body is node 357, `message` is 714, the bid is progressive and its first chunk
/// `parent_block_hash` is 714 * 4 = 2856 (`specs/gloas/light-client/sync-protocol.md`, `EXECUTION_BLOCK_HASH_GINDEX_GLOAS`).
/// The branch has 11 entries. The position is fixed by the progressive layout, so no layout evidence names it.
///
/// The rule for a message source whose state the fork proof shows to be progressive: the source header is a beacon
/// block B AFTER the block of the proven execution block X, and `parent_block_hash` of B equals the hash of X. Why it is
/// sound:
/// `process_execution_payload_bid` asserts `bid.parent_block_hash == state.latest_block_hash`, and `latest_block_hash` is
/// written only by `apply_parent_execution_payload`, from the bid of a parent whose payload the child confirmed. So the
/// `parent_block_hash` of a block of the canonical chain names a payload that the chain accepted. A block on an empty
/// parent names an older accepted payload, which is canonical too. The bid's own `block_hash` is never accepted: that
/// payload may be withheld. B must be an ancestor of the stored head, which the ancestry branch proves.
uint256 private constant GLOAS_BID_PARENT_BLOCK_HASH_GINDEX = 2856;
/// @dev The position of `BeaconState.historical_summaries` in the progressive Gloas state: field 27 is chunk 27, the
/// seventh leaf of the 64 leaf subtree at node 46, which starts at 2944.
uint256 private constant GLOAS_HISTORICAL_SUMMARIES_GINDEX = 2950;
/// @dev The deepest accepted block hash position.
uint256 private constant MAX_BLOCK_HASH_DEPTH = 16;
/// @dev The index of `BeaconState.block_roots` among the state fields.
uint256 private constant BLOCK_ROOTS_FIELD = 5;
/// @dev The index of `BeaconState.historical_summaries` among the state fields (Capella through Fulu).
uint256 private constant HISTORICAL_SUMMARIES_FIELD = 27;
/// @dev The index of `execution_payload` among the `BeaconBlockBody` fields (Capella through Fulu).
uint256 private constant EXECUTION_PAYLOAD_FIELD = 9;
/// @dev The index of `block_hash` among the `ExecutionPayload` fields (Capella through Fulu).
uint256 private constant BLOCK_HASH_FIELD = 12;
// The accepted depths of the `BeaconState` tree are the plain shapes of `ForkShape.allowedShapes` (5, 6 and 7: 32, 64
// or 128 leaves), and the fixed Gloas positions count only while `ForkShape.PROGRESSIVE` is allowed. No second list.
/// @dev The accepted depths of the `BeaconBlockBody` tree (16 or 32 leaves) and of the `ExecutionPayload` tree
/// (16 or 32 leaves).
uint256 private constant MIN_BODY_DEPTH = 4;
uint256 private constant MAX_BODY_DEPTH = 5;
uint256 private constant MIN_PAYLOAD_DEPTH = 4;
uint256 private constant MAX_PAYLOAD_DEPTH = 5;
uint64 private constant SLOTS_PER_HISTORICAL_ROOT = ERA_SLOTS;
uint256 private constant BLOCK_ROOTS_VECTOR_DEPTH = ERA_DEPTH;
uint256 private constant HISTORICAL_SUMMARIES_LIST_DEPTH = HISTORICAL_LIST_DEPTH;
// ------------------------------------------------------------------ adding layouts
/// @notice The body of `BeaconProofVerifier.addBlockRootsLayout`.
function addBlockRootsLayout(
BeaconProofVerifier.SlotRange[] storage table,
IBeaconLightClient lightClient,
uint256 blockRootsGindex,
BeaconProofVerifier.BlockRootsEvidence calldata evidence
) external {
if (blockRootsGindex == 0 || SSZ.depthOf(blockRootsGindex) > MAX_BLOCK_ROOTS_DEPTH) {
revert BeaconProofVerifier.LayoutOutOfBounds(blockRootsGindex);
}
if (!_isBlockRootsPosition(blockRootsGindex)) {
revert BeaconProofVerifier.LayoutPositionInvalid(blockRootsGindex);
}
_requireStoredHeader(lightClient, evidence.laterHeader);
if (evidence.earlierSlotA == evidence.earlierSlotB) {
revert BeaconProofVerifier.EvidenceSlotsEqual(evidence.earlierSlotA);
}
_requireEarlierRoot(
lightClient, evidence.laterHeader, evidence.earlierSlotA, blockRootsGindex, evidence.branchA
);
_requireEarlierRoot(
lightClient, evidence.laterHeader, evidence.earlierSlotB, blockRootsGindex, evidence.branchB
);
(uint64 firstSlot, uint64 lastSlot) = _record(table, blockRootsGindex, evidence.laterHeader.slot);
emit BeaconProofVerifier.BlockRootsLayoutValidated(blockRootsGindex, firstSlot, lastSlot);
}
/// @notice The body of `BeaconProofVerifier.addBlockHashLayout`.
function addBlockHashLayout(
BeaconProofVerifier.SlotRange[] storage table,
IBeaconLightClient lightClient,
uint256 blockHashGindex,
BeaconProofVerifier.BlockHashEvidence calldata evidence
) external {
if (blockHashGindex == 0 || SSZ.depthOf(blockHashGindex) > MAX_BLOCK_HASH_DEPTH) {
revert BeaconProofVerifier.LayoutOutOfBounds(blockHashGindex);
}
if (!_isBlockHashPosition(blockHashGindex)) revert BeaconProofVerifier.LayoutPositionInvalid(blockHashGindex);
_requireStoredHeader(lightClient, evidence.header);
uint64 slot = evidence.header.slot;
bytes32 storedBlockHash = lightClient.executionBlockHashes(slot);
if (storedBlockHash == bytes32(0)) revert BeaconProofVerifier.EvidenceSlotNotStored(slot);
if (_provenShape(lightClient, evidence.header.stateRoot, evidence.fork) == ForkShape.PROGRESSIVE) {
revert BeaconProofVerifier.GloasSlotRefused(slot);
}
if (!SSZ.isValidBranch(storedBlockHash, evidence.branch, blockHashGindex, evidence.header.bodyRoot)) {
revert BeaconProofVerifier.LayoutEvidenceInvalid();
}
(uint64 firstSlot, uint64 lastSlot) = _record(table, blockHashGindex, slot);
emit BeaconProofVerifier.BlockHashLayoutValidated(blockHashGindex, firstSlot, lastSlot);
}
/// @notice The body of `BeaconProofVerifier.addHistoricalSummariesLayout`.
function addHistoricalSummariesLayout(
BeaconProofVerifier.SlotRange[] storage table,
IBeaconLightClient lightClient,
uint64 capellaEra,
uint256 historicalSummariesGindex,
BeaconProofVerifier.HistoricalSummariesEvidence calldata evidence
) external {
if (
historicalSummariesGindex == 0
|| (SSZ.depthOf(historicalSummariesGindex) > MAX_BLOCK_ROOTS_DEPTH
&& historicalSummariesGindex != GLOAS_HISTORICAL_SUMMARIES_GINDEX)
) {
revert BeaconProofVerifier.LayoutOutOfBounds(historicalSummariesGindex);
}
if (!_isHistoricalSummariesPosition(historicalSummariesGindex)) {
revert BeaconProofVerifier.LayoutPositionInvalid(historicalSummariesGindex);
}
_requireStoredHeader(lightClient, evidence.anchorHeader);
uint64 anchorSlot = evidence.anchorHeader.slot;
uint64 earlierSlot = evidence.earlierSlot;
bytes32 storedRoot = lightClient.headers(earlierSlot);
if (storedRoot == bytes32(0)) revert BeaconProofVerifier.EvidenceSlotNotStored(earlierSlot);
if (earlierSlot >= anchorSlot || anchorSlot - earlierSlot <= SLOTS_PER_HISTORICAL_ROOT) {
revert BeaconProofVerifier.EvidenceSlotNotHistorical(earlierSlot, anchorSlot);
}
uint256 leafIndex =
_historicalLeafGindex(historicalSummariesGindex, _eraIndex(capellaEra, earlierSlot), earlierSlot);
if (!SSZ.isValidBranch(storedRoot, evidence.branch, leafIndex, evidence.anchorHeader.stateRoot)) {
revert BeaconProofVerifier.LayoutEvidenceInvalid();
}
(uint64 firstSlot, uint64 lastSlot) = _record(table, historicalSummariesGindex, anchorSlot);
emit BeaconProofVerifier.HistoricalSummariesLayoutValidated(historicalSummariesGindex, firstSlot, lastSlot);
}
/// @dev Records that `gindex` was validated at `slot`, by the range rule (`planRange`): a new row, or a row of the same
/// position that grows to hold the slot. Returns the range of that row after the change.
function _record(BeaconProofVerifier.SlotRange[] storage table, uint256 gindex, uint64 slot)
private
returns (uint64 firstSlot, uint64 lastSlot)
{
BeaconProofVerifier.SlotRange[] memory ranges = table;
uint256 index = planRange(gindex, slot, ranges);
if (index == ranges.length) {
table.push(BeaconProofVerifier.SlotRange({gindex: gindex, firstSlot: slot, lastSlot: slot}));
return (slot, slot);
}
BeaconProofVerifier.SlotRange storage row = table[index];
if (slot < row.firstSlot) row.firstSlot = slot;
if (slot > row.lastSlot) row.lastSlot = slot;
return (row.firstSlot, row.lastSlot);
}
// ------------------------------------------------------------------ checks of a delivery
/// @notice Checks 1 to 3 of a delivery: the anchor is the header that the light client stored for its slot, and the
/// source block is its ancestor. The path comes from the distance: up to 8192 slots is the recent path through
/// `block_roots`, more is the historical path through `historical_summaries`. The prover never picks. Both leaf
/// indices are built by pure functions, and the branch length must be exact (`SSZ.isValidBranch` refuses padding and
/// short branches).
/// @param anchorHeader A header that the light client stored.
/// @param sourceHeader The beacon block that carries the proven execution block.
/// @param branch The branch from the root of `sourceHeader` to the state root of the anchor.
function requireAncestry(
BeaconProofVerifier.LayoutTables storage tables,
IBeaconLightClient lightClient,
uint64 capellaEra,
BeaconBlockHeader calldata anchorHeader,
BeaconBlockHeader calldata sourceHeader,
bytes32[] calldata branch
) external view {
_requireStoredHeader(lightClient, anchorHeader);
uint64 anchorSlot = anchorHeader.slot;
uint64 depositSlot = sourceHeader.slot;
if (depositSlot >= anchorSlot) revert BeaconProofVerifier.DepositNotBeforeAnchor(depositSlot, anchorSlot);
uint256 leafIndex = anchorSlot - depositSlot <= SLOTS_PER_HISTORICAL_ROOT
? _gindexAt(tables.states, anchorSlot) * SLOTS_PER_HISTORICAL_ROOT
+ (depositSlot % SLOTS_PER_HISTORICAL_ROOT)
: _historicalLeafGindex(
_gindexAt(tables.historicals, anchorSlot), _eraIndex(capellaEra, depositSlot), depositSlot
);
bytes32 sourceRoot = SSZ.hashTreeRoot(sourceHeader);
if (!SSZ.isValidBranch(sourceRoot, branch, leafIndex, anchorHeader.stateRoot)) {
revert BeaconProofVerifier.AncestryBranchInvalid();
}
}
/// @notice Check 4 of a delivery: the execution block hash sits in the body of the source header. The fork proof of the
/// source state picks the rule first. A plain shape (before Gloas) takes the validated payload block hash position of
/// the slot. The progressive shape (Gloas on) takes the bid `parent_block_hash` at the fixed index 2856 (see
/// `GLOAS_BID_PARENT_BLOCK_HASH_GINDEX`). The state root comes from the source header, whose root check 3 already tied
/// to a stored head, so the prover cannot pick another state.
function requireBlockHash(
BeaconProofVerifier.SlotRange[] storage bodies,
IBeaconLightClient lightClient,
bytes32 blockHash,
BeaconBlockHeader calldata sourceHeader,
bytes32[] calldata branch,
BeaconProofVerifier.ForkProof calldata sourceFork
) external view {
uint256 gindex = _provenShape(lightClient, sourceHeader.stateRoot, sourceFork) == ForkShape.PROGRESSIVE
? GLOAS_BID_PARENT_BLOCK_HASH_GINDEX
: _gindexAt(bodies, sourceHeader.slot);
if (!SSZ.isValidBranch(blockHash, branch, gindex, sourceHeader.bodyRoot)) {
revert BeaconProofVerifier.BlockHashBranchInvalid();
}
}
/// @dev The shape of the state under `stateRoot`, by the rule of the deposit gate (`ForkShape.judge`), with the genesis
/// validators root of the light client. Reverts unless the shape is in `ForkShape.allowedShapes`.
///
/// Why the prover cannot claim the other shape. The genesis validators root leaf of each shape lies where the other
/// shapes hold a fixed leaf or a hash: every plain position (33, 65, 129) lies under node 4, which is the leaf
/// `genesis_time` in the progressive state, and the progressive position 40 is the root of `eth1_data` (depth 5) or an
/// inner node (depth 6, 7) of a plain state. So a valid branch for the wrong shape needs a SHA-256 preimage.
function _provenShape(
IBeaconLightClient lightClient,
bytes32 stateRoot,
BeaconProofVerifier.ForkProof calldata fork
) private view returns (uint8) {
(ForkShape.Verdict verdict, uint8 shape) = ForkShape.judge(
stateRoot,
fork.version,
fork.versionBranch,
fork.genesisValidatorsRootBranch,
lightClient.genesisValidatorsRoot()
);
if (verdict != ForkShape.Verdict.Allowed) revert BeaconProofVerifier.ForkShapeProofInvalid(uint8(verdict));
return shape;
}
/// @dev The validated position of a layout table whose slot range contains `slot`.
function _gindexAt(BeaconProofVerifier.SlotRange[] storage table, uint64 slot) private view returns (uint256) {
for (uint256 i = 0; i < table.length; i++) {
BeaconProofVerifier.SlotRange storage row = table[i];
if (row.firstSlot <= slot && slot <= row.lastSlot) return row.gindex;
}
revert BeaconProofVerifier.LayoutNotValidated(slot);
}
// ------------------------------------------------------------------ rules (internal, also used by tests)
/// @dev The range rule. Returns the index of the range of `gindex` that grows to hold `slot`, or `ranges.length`
/// when a new range must start. A range grows only when the grown range overlaps no range of another position, so
/// ranges of different positions never overlap. Reverts when `slot` is already inside the range of another position.
function planRange(uint256 gindex, uint64 slot, BeaconProofVerifier.SlotRange[] memory ranges)
internal
pure
returns (uint256)
{
for (uint256 i = 0; i < ranges.length; i++) {
if (ranges[i].gindex == gindex) continue;
if (ranges[i].firstSlot <= slot && slot <= ranges[i].lastSlot) {
revert BeaconProofVerifier.LayoutRangeConflict(slot);
}
}
for (uint256 i = 0; i < ranges.length; i++) {
if (ranges[i].gindex != gindex) continue;
uint64 low = slot < ranges[i].firstSlot ? slot : ranges[i].firstSlot;
uint64 high = slot > ranges[i].lastSlot ? slot : ranges[i].lastSlot;
if (_overlapsOtherPosition(gindex, low, high, ranges)) continue;
return i;
}
return ranges.length;
}
/// @dev Whether a range of a position other than `gindex` shares a slot with `low` to `high`.
function _overlapsOtherPosition(
uint256 gindex,
uint64 low,
uint64 high,
BeaconProofVerifier.SlotRange[] memory ranges
) private pure returns (bool) {
for (uint256 i = 0; i < ranges.length; i++) {
if (ranges[i].gindex == gindex) continue;
if (ranges[i].firstSlot <= high && low <= ranges[i].lastSlot) return true;
}
return false;
}
/// @dev Whether `gindex` is `BeaconState.block_roots` in a state of an allowed shape: field 5 of a plain tree (37, 69,
/// 133 for depth 5, 6, 7), or 352 in the progressive state.
function _isBlockRootsPosition(uint256 gindex) private pure returns (bool) {
return _isStateFieldPosition(gindex, BLOCK_ROOTS_FIELD, GLOAS_BLOCK_ROOTS_GINDEX);
}
/// @dev Whether `gindex` is `BeaconState.historical_summaries` in a state of an allowed shape: field 27 of a plain tree
/// (59, 91, 155), or 2950 in the progressive state.
function _isHistoricalSummariesPosition(uint256 gindex) private pure returns (bool) {
return _isStateFieldPosition(gindex, HISTORICAL_SUMMARIES_FIELD, GLOAS_HISTORICAL_SUMMARIES_GINDEX);
}
/// @dev Whether `gindex` is the position of a state field for one of the shapes of `ForkShape.allowedShapes`, the list
/// of the deposit gate: `2**shape + fieldIndex` for a plain shape, `progressiveGindex` for the progressive one. A shape
/// added to or removed from that list adds or removes its positions here, with no second list.
function _isStateFieldPosition(uint256 gindex, uint256 fieldIndex, uint256 progressiveGindex)
private
pure
returns (bool)
{
uint8[] memory shapes = ForkShape.allowedShapes();
for (uint256 i = 0; i < shapes.length; i++) {
uint256 position =
shapes[i] == ForkShape.PROGRESSIVE ? progressiveGindex : (uint256(1) << shapes[i]) + fieldIndex;
if (gindex == position) return true;
}
return false;
}
/// @dev Whether `gindex` is `ExecutionPayload.block_hash` inside `BeaconBlockBody.execution_payload`:
/// `(2**bodyDepth + 9) * 2**payloadDepth + 12`, with both depths in 4 to 5.
function _isBlockHashPosition(uint256 gindex) private pure returns (bool) {
for (uint256 bodyDepth = MIN_BODY_DEPTH; bodyDepth <= MAX_BODY_DEPTH; bodyDepth++) {
uint256 payloadField = (uint256(1) << bodyDepth) + EXECUTION_PAYLOAD_FIELD;
for (uint256 payloadDepth = MIN_PAYLOAD_DEPTH; payloadDepth <= MAX_PAYLOAD_DEPTH; payloadDepth++) {
if (gindex == (payloadField << payloadDepth) + BLOCK_HASH_FIELD) return true;
}
}
return false;
}
/// @dev A header must equal the finalized header that the light client stored for its slot.
function _requireStoredHeader(IBeaconLightClient lightClient, BeaconBlockHeader calldata header) private view {
bytes32 headerRoot = SSZ.hashTreeRoot(header);
bytes32 stored = lightClient.headers(header.slot);
if (stored == bytes32(0) || stored != headerRoot) {
revert BeaconProofVerifier.AnchorNotStored(header.slot, headerRoot);
}
}
/// @dev The stored root at `earlierSlot` must be the leaf at the candidate position under the later state root.
function _requireEarlierRoot(
IBeaconLightClient lightClient,
BeaconBlockHeader calldata later,
uint64 earlierSlot,
uint256 blockRootsGindex,
bytes32[] calldata branch
) private view {
if (earlierSlot >= later.slot || later.slot - earlierSlot > SLOTS_PER_HISTORICAL_ROOT) {
revert BeaconProofVerifier.EvidenceSlotOutOfWindow(earlierSlot, later.slot);
}
bytes32 storedRoot = lightClient.headers(earlierSlot);
if (storedRoot == bytes32(0)) revert BeaconProofVerifier.EvidenceSlotNotStored(earlierSlot);
uint256 elementIndex = blockRootsGindex * SLOTS_PER_HISTORICAL_ROOT + (earlierSlot % SLOTS_PER_HISTORICAL_ROOT);
if (!SSZ.isValidBranch(storedRoot, branch, elementIndex, later.stateRoot)) {
revert BeaconProofVerifier.LayoutEvidenceInvalid();
}
}
/// @dev The index of the summary of a slot's era: `era - capellaEra`. The era must be at or after `capellaEra`
/// and the index must fit the list of 2**24 entries.
function _eraIndex(uint64 capellaEra, uint64 slot) private pure returns (uint64) {
uint64 era = slot / SLOTS_PER_HISTORICAL_ROOT;
if (era < capellaEra) revert BeaconProofVerifier.DepositBeforeCapellaEra(era, capellaEra);
uint64 index = era - capellaEra;
if (uint256(index) >= (uint256(1) << HISTORICAL_SUMMARIES_LIST_DEPTH)) {
revert BeaconProofVerifier.HistoricalIndexOutOfRange(index);
}
return index;
}
/// @dev The historical path. Built in this order, from the index `g` of `historical_summaries` in `BeaconState`:
/// 1. `g` is the field. 2. `g = g * 2`: the list data root, past the length mix-in.
/// 3. `g = g * 2**24 + index`: the list position. 4. `g = g * 2 + 0`: `HistoricalSummary.block_summary_root`.
/// 5. `g = g * 2**13 + depositSlot % 8192`: the position inside that era's `block_roots`.
function _historicalLeafGindex(uint256 historicalSummariesGindex, uint64 index, uint64 depositSlot)
private
pure
returns (uint256 gindex)
{
gindex = historicalSummariesGindex;
gindex = gindex * 2;
gindex = gindex * (uint256(1) << HISTORICAL_SUMMARIES_LIST_DEPTH) + index;
gindex = gindex * 2 + 0;
gindex = gindex * (uint256(1) << BLOCK_ROOTS_VECTOR_DEPTH) + (depositSlot % SLOTS_PER_HISTORICAL_ROOT);
}
}
src/hardened/vendor/optimism/Bytes.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Bytes
/// @notice Bytes is a library for manipulating byte arrays.
library Bytes {
/// @custom:attribution https://github.com/GNSPS/solidity-bytes-utils
/// @notice Slices a byte array with a given starting index and length. Returns a new byte array
/// as opposed to a pointer to the original array. Will throw if trying to slice more
/// bytes than exist in the array.
/// @param _bytes Byte array to slice.
/// @param _start Starting index of the slice.
/// @param _length Length of the slice.
/// @return Slice of the input byte array.
function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory) {
unchecked {
require(_length + 31 >= _length, "slice_overflow");
require(_start + _length >= _start, "slice_overflow");
require(_bytes.length >= _start + _length, "slice_outOfBounds");
}
bytes memory tempBytes;
assembly {
switch iszero(_length)
case 0 {
// Get a location of some free memory and store it in tempBytes as
// Solidity does for memory variables.
tempBytes := mload(0x40)
// The first word of the slice result is potentially a partial
// word read from the original array. To read it, we calculate
// the length of that partial word and start copying that many
// bytes into the array. The first word we copy will start with
// data we don't care about, but the last `lengthmod` bytes will
// land at the beginning of the contents of the new array. When
// we're done copying, we overwrite the full first word with
// the actual length of the slice.
let lengthmod := and(_length, 31)
// The multiplication in the next line is necessary
// because when slicing multiples of 32 bytes (lengthmod == 0)
// the following copy loop was copying the origin's length
// and then ending prematurely not copying everything it should.
let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
let end := add(mc, _length)
for {
// The multiplication in the next line has the same exact purpose
// as the one above.
let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
} lt(mc, end) {
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} { mstore(mc, mload(cc)) }
mstore(tempBytes, _length)
//update free-memory pointer
//allocating the array padded to 32 bytes like the compiler does now
mstore(0x40, and(add(mc, 31), not(31)))
}
//if we want a zero-length slice let's just return a zero-length array
default {
tempBytes := mload(0x40)
//zero out the 32 bytes slice we are about to return
//we need to do it because Solidity does not garbage collect
mstore(tempBytes, 0)
mstore(0x40, add(tempBytes, 0x20))
}
}
return tempBytes;
}
/// @notice Slices a byte array with a given starting index up to the end of the original byte
/// array. Returns a new array rather than a pointer to the original.
/// @param _bytes Byte array to slice.
/// @param _start Starting index of the slice.
/// @return Slice of the input byte array.
function slice(bytes memory _bytes, uint256 _start) internal pure returns (bytes memory) {
if (_start >= _bytes.length) {
return bytes("");
}
return slice(_bytes, _start, _bytes.length - _start);
}
/// @notice Converts a byte array into a nibble array by splitting each byte into two nibbles.
/// Resulting nibble array will be exactly twice as long as the input byte array.
/// @param _bytes Input byte array to convert.
/// @return Resulting nibble array.
function toNibbles(bytes memory _bytes) internal pure returns (bytes memory) {
bytes memory _nibbles;
assembly {
// Grab a free memory offset for the new array
_nibbles := mload(0x40)
// Load the length of the passed bytes array from memory
let bytesLength := mload(_bytes)
// Calculate the length of the new nibble array
// This is the length of the input array times 2
let nibblesLength := shl(0x01, bytesLength)
// Update the free memory pointer to allocate memory for the new array.
// To do this, we add the length of the new array + 32 bytes for the array length
// rounded up to the nearest 32 byte boundary to the current free memory pointer.
mstore(0x40, add(_nibbles, and(not(0x1F), add(nibblesLength, 0x3F))))
// Store the length of the new array in memory
mstore(_nibbles, nibblesLength)
// Store the memory offset of the _bytes array's contents on the stack
let bytesStart := add(_bytes, 0x20)
// Store the memory offset of the nibbles array's contents on the stack
let nibblesStart := add(_nibbles, 0x20)
// Loop through each byte in the input array
for { let i := 0x00 } lt(i, bytesLength) { i := add(i, 0x01) } {
// Get the starting offset of the next 2 bytes in the nibbles array
let offset := add(nibblesStart, shl(0x01, i))
// Load the byte at the current index within the `_bytes` array
let b := byte(0x00, mload(add(bytesStart, i)))
// Pull out the first nibble and store it in the new array
mstore8(offset, shr(0x04, b))
// Pull out the second nibble and store it in the new array
mstore8(add(offset, 0x01), and(b, 0x0F))
}
}
return _nibbles;
}
/// @notice Compares two byte arrays by comparing their keccak256 hashes.
/// @param _bytes First byte array to compare.
/// @param _other Second byte array to compare.
/// @return True if the two byte arrays are equal, false otherwise.
function equal(bytes memory _bytes, bytes memory _other) internal pure returns (bool) {
return keccak256(_bytes) == keccak256(_other);
}
}
src/hardened/OpeningProofLib.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {MerkleTrie} from "./vendor/optimism/trie/MerkleTrie.sol";
import {RLPReader} from "./vendor/optimism/rlp/RLPReader.sol";
import {BeaconProofVerifier} from "./BeaconProofVerifier.sol";
/// @title OpeningProofLib
/// @notice The execution layer part of the opening proof of the message bridge (`openDeposits`): the state root of the
/// proven header, the account of the remote light client, and its `executionBlockHashes` entry. All of it is pure.
/// @dev An external library, linked into `MessageBridge`, so that each contract creation of the bridge stays under the
/// per-transaction gas cap of EIP-7825 (16,777,216). It has no owner and no storage, and its address is fixed in the
/// bytecode of the bridge, so the bridge stays immutable. It reverts with the errors of `BeaconProofVerifier`.
library OpeningProofLib {
/// @dev The index of `stateRoot` in the execution block header list.
uint256 internal constant STATE_ROOT_FIELD = 3;
/// @dev The index of `storageRoot` in an account (nonce, balance, storage root, code hash).
uint256 internal constant ACCOUNT_STORAGE_ROOT_FIELD = 2;
/// @dev The storage slot of the mapping `executionBlockHashes` in `BeaconLightClient`.
uint256 internal constant EXECUTION_BLOCK_HASHES_MAPPING_SLOT = 3;
/// @notice Links 2 to 4 of the opening proof, after the caller checked that `remoteHeaderRlp` hashes to the stored
/// block hash: the header holds a state root; under it, the account of `remoteLightClient` holds a storage root;
/// under that, `executionBlockHashes[storedSlot]` is not zero.
function requireOpeningEntry(
bytes calldata remoteHeaderRlp,
bytes[] calldata accountProof,
uint64 storedSlot,
bytes[] calldata storageProof,
address remoteLightClient
) external pure {
bytes32 stateRoot = headerField(remoteHeaderRlp, STATE_ROOT_FIELD);
bytes memory account =
MerkleTrie.get(abi.encodePacked(keccak256(abi.encodePacked(remoteLightClient))), accountProof, stateRoot);
bytes32 storageRoot = accountStorageRoot(account);
bytes memory entry = MerkleTrie.get(
abi.encodePacked(keccak256(abi.encode(executionBlockHashesSlot(storedSlot)))), storageProof, storageRoot
);
if (RLPReader.readBytes(entry).length == 0) revert BeaconProofVerifier.OpeningEntryEmpty(storedSlot);
}
/// @dev The storage slot of `executionBlockHashes[storedSlot]` in the remote light client: the mapping key and the
/// declared slot of the mapping, hashed together.
function executionBlockHashesSlot(uint64 storedSlot) internal pure returns (bytes32) {
return keccak256(abi.encode(uint256(storedSlot), EXECUTION_BLOCK_HASHES_MAPPING_SLOT));
}
/// @dev The 32-byte item at index `field` of an execution block header.
function headerField(bytes calldata headerRlp, uint256 field) internal pure returns (bytes32) {
RLPReader.RLPItem[] memory fields = RLPReader.readList(headerRlp);
if (fields.length <= field) revert BeaconProofVerifier.OpeningProofMalformed();
bytes memory value = RLPReader.readBytes(fields[field]);
if (value.length != 32) revert BeaconProofVerifier.OpeningProofMalformed();
return bytes32(value);
}
/// @dev The storage root of an account, from its RLP: nonce, balance, storage root and code hash.
function accountStorageRoot(bytes memory account) internal pure returns (bytes32) {
RLPReader.RLPItem[] memory fields = RLPReader.readList(account);
if (fields.length != 4) revert BeaconProofVerifier.OpeningProofMalformed();
bytes memory root = RLPReader.readBytes(fields[ACCOUNT_STORAGE_ROOT_FIELD]);
if (root.length != 32) revert BeaconProofVerifier.OpeningProofMalformed();
return bytes32(root);
}
}
Compiler Settings
{"viaIR":false,"remappings":["@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/","forge-std/=lib/forge-std/src/","erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/","halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/","openzeppelin-contracts/=lib/openzeppelin-contracts/"],"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode"]}},"optimizer":{"runs":200,"enabled":true},"metadata":{"useLiteralContent":false,"bytecodeHash":"none","appendCBOR":false},"libraries":{"src/hardened/ReceiptProofLib.sol":{"ReceiptProofLib":"0x5a5ff919270c2776cbf6db3f13228267938466ae"},"src/hardened/OpeningProofLib.sol":{"OpeningProofLib":"0xb3d7d5d954b3ddb01b7020c34b669ac118113427"},"src/hardened/BeaconLayoutLib.sol":{"BeaconLayoutLib":"0xb8b1b2c701aff6bfc4538a958dd58abc4dea4eb6"}},"evmVersion":"shanghai"}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"lightClient_","internalType":"address"},{"type":"uint64","name":"remoteChainId_","internalType":"uint64"},{"type":"address","name":"remoteBridge_","internalType":"address"},{"type":"tuple","name":"bridgeTerms","internalType":"struct MessageBridge.BridgeTerms","components":[{"type":"uint64","name":"cutoffTimestamp","internalType":"uint64"},{"type":"address","name":"remoteLightClient","internalType":"address"}]},{"type":"uint64","name":"capellaEra_","internalType":"uint64"},{"type":"address","name":"depositGate_","internalType":"address"}]},{"type":"error","name":"AlreadyDelivered","inputs":[{"type":"bytes32","name":"messageId","internalType":"bytes32"}]},{"type":"error","name":"AncestryBranchInvalid","inputs":[]},{"type":"error","name":"AnchorNotStored","inputs":[{"type":"uint64","name":"slot","internalType":"uint64"},{"type":"bytes32","name":"anchorRoot","internalType":"bytes32"}]},{"type":"error","name":"BlockHashBranchInvalid","inputs":[]},{"type":"error","name":"DepositBeforeCapellaEra","inputs":[{"type":"uint64","name":"depositEra","internalType":"uint64"},{"type":"uint64","name":"capellaEra","internalType":"uint64"}]},{"type":"error","name":"DepositNotBeforeAnchor","inputs":[{"type":"uint64","name":"depositSlot","internalType":"uint64"},{"type":"uint64","name":"anchorSlot","internalType":"uint64"}]},{"type":"error","name":"DepositsNotOpen","inputs":[]},{"type":"error","name":"EvidenceSlotNotHistorical","inputs":[{"type":"uint64","name":"earlierSlot","internalType":"uint64"},{"type":"uint64","name":"anchorSlot","internalType":"uint64"}]},{"type":"error","name":"EvidenceSlotNotStored","inputs":[{"type":"uint64","name":"slot","internalType":"uint64"}]},{"type":"error","name":"EvidenceSlotOutOfWindow","inputs":[{"type":"uint64","name":"earlierSlot","internalType":"uint64"},{"type":"uint64","name":"laterSlot","internalType":"uint64"}]},{"type":"error","name":"EvidenceSlotsEqual","inputs":[{"type":"uint64","name":"slot","internalType":"uint64"}]},{"type":"error","name":"ForbiddenSelector","inputs":[{"type":"bytes4","name":"selector","internalType":"bytes4"}]},{"type":"error","name":"ForkShapeProofInvalid","inputs":[{"type":"uint8","name":"verdict","internalType":"uint8"}]},{"type":"error","name":"GloasSlotRefused","inputs":[{"type":"uint64","name":"slot","internalType":"uint64"}]},{"type":"error","name":"HistoricalIndexOutOfRange","inputs":[{"type":"uint64","name":"index","internalType":"uint64"}]},{"type":"error","name":"IndexMismatch","inputs":[{"type":"uint256","name":"receiptIndex","internalType":"uint256"},{"type":"uint256","name":"transactionIndex","internalType":"uint256"}]},{"type":"error","name":"LayoutEvidenceInvalid","inputs":[]},{"type":"error","name":"LayoutNotValidated","inputs":[{"type":"uint64","name":"slot","internalType":"uint64"}]},{"type":"error","name":"LayoutOutOfBounds","inputs":[{"type":"uint256","name":"gindex","internalType":"uint256"}]},{"type":"error","name":"LayoutPositionInvalid","inputs":[{"type":"uint256","name":"gindex","internalType":"uint256"}]},{"type":"error","name":"LayoutRangeConflict","inputs":[{"type":"uint64","name":"slot","internalType":"uint64"}]},{"type":"error","name":"LocalChainIdTooLarge","inputs":[{"type":"uint256","name":"chainId","internalType":"uint256"}]},{"type":"error","name":"LogIndexOutOfRange","inputs":[{"type":"uint256","name":"logIndex","internalType":"uint256"},{"type":"uint256","name":"logCount","internalType":"uint256"}]},{"type":"error","name":"MalformedEventData","inputs":[]},{"type":"error","name":"MalformedExecutionHeader","inputs":[]},{"type":"error","name":"MalformedLog","inputs":[]},{"type":"error","name":"MalformedMessage","inputs":[]},{"type":"error","name":"MalformedReceipt","inputs":[]},{"type":"error","name":"MessageIdMismatch","inputs":[{"type":"bytes32","name":"topicMessageId","internalType":"bytes32"},{"type":"bytes32","name":"encodedMessageId","internalType":"bytes32"}]},{"type":"error","name":"MessageInProgress","inputs":[{"type":"bytes32","name":"messageId","internalType":"bytes32"}]},{"type":"error","name":"MessageVersionInvalid","inputs":[{"type":"bytes32","name":"messageId","internalType":"bytes32"}]},{"type":"error","name":"OpeningEntryEmpty","inputs":[{"type":"uint64","name":"storedSlot","internalType":"uint64"}]},{"type":"error","name":"OpeningHeaderMismatch","inputs":[{"type":"bytes32","name":"expected","internalType":"bytes32"},{"type":"bytes32","name":"actual","internalType":"bytes32"}]},{"type":"error","name":"OpeningProofMalformed","inputs":[]},{"type":"error","name":"OpeningSlotNotStored","inputs":[{"type":"uint64","name":"slot","internalType":"uint64"}]},{"type":"error","name":"ReceiptFailed","inputs":[]},{"type":"error","name":"RemoteChainIsLocalChain","inputs":[]},{"type":"error","name":"SendCutoffReached","inputs":[{"type":"uint64","name":"cutoff","internalType":"uint64"}]},{"type":"error","name":"TargetCallFailed","inputs":[{"type":"bytes32","name":"messageId","internalType":"bytes32"}]},{"type":"error","name":"UnknownDataType","inputs":[{"type":"uint8","name":"dataType","internalType":"uint8"}]},{"type":"error","name":"WrongDestinationChain","inputs":[{"type":"uint64","name":"expected","internalType":"uint64"},{"type":"uint256","name":"actual","internalType":"uint256"}]},{"type":"error","name":"WrongEmitter","inputs":[{"type":"address","name":"expected","internalType":"address"},{"type":"address","name":"actual","internalType":"address"}]},{"type":"error","name":"WrongEventTopic","inputs":[{"type":"bytes32","name":"actual","internalType":"bytes32"}]},{"type":"error","name":"WrongSourceChain","inputs":[{"type":"uint64","name":"expected","internalType":"uint64"},{"type":"uint256","name":"actual","internalType":"uint256"}]},{"type":"error","name":"ZeroValue","inputs":[{"type":"string","name":"name","internalType":"string"}]},{"type":"event","name":"AffirmationCompleted","inputs":[{"type":"address","name":"sender","internalType":"address","indexed":true},{"type":"address","name":"executor","internalType":"address","indexed":true},{"type":"bytes32","name":"messageId","internalType":"bytes32","indexed":true},{"type":"bool","name":"status","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"BlockHashLayoutValidated","inputs":[{"type":"uint256","name":"blockHashGindex","internalType":"uint256","indexed":true},{"type":"uint64","name":"firstSlot","internalType":"uint64","indexed":false},{"type":"uint64","name":"lastSlot","internalType":"uint64","indexed":false}],"anonymous":false},{"type":"event","name":"BlockRootsLayoutValidated","inputs":[{"type":"uint256","name":"blockRootsGindex","internalType":"uint256","indexed":true},{"type":"uint64","name":"firstSlot","internalType":"uint64","indexed":false},{"type":"uint64","name":"lastSlot","internalType":"uint64","indexed":false}],"anonymous":false},{"type":"event","name":"DepositsOpened","inputs":[{"type":"uint64","name":"remoteSlot","internalType":"uint64","indexed":true},{"type":"bytes32","name":"remoteBlockHash","internalType":"bytes32","indexed":true},{"type":"uint64","name":"storedSlot","internalType":"uint64","indexed":false}],"anonymous":false},{"type":"event","name":"HistoricalSummariesLayoutValidated","inputs":[{"type":"uint256","name":"historicalSummariesGindex","internalType":"uint256","indexed":true},{"type":"uint64","name":"firstSlot","internalType":"uint64","indexed":false},{"type":"uint64","name":"lastSlot","internalType":"uint64","indexed":false}],"anonymous":false},{"type":"event","name":"RelayedMessage","inputs":[{"type":"address","name":"sender","internalType":"address","indexed":true},{"type":"address","name":"executor","internalType":"address","indexed":true},{"type":"bytes32","name":"messageId","internalType":"bytes32","indexed":true},{"type":"bool","name":"status","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"UserRequestForAffirmation","inputs":[{"type":"bytes32","name":"messageId","internalType":"bytes32","indexed":true},{"type":"bytes","name":"encodedData","internalType":"bytes","indexed":false}],"anonymous":false},{"type":"event","name":"UserRequestForSignature","inputs":[{"type":"bytes32","name":"messageId","internalType":"bytes32","indexed":true},{"type":"bytes","name":"encodedData","internalType":"bytes","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"BLOCK_ROOTS_VECTOR_DEPTH","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"HISTORICAL_SUMMARIES_LIST_DEPTH","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"SLOTS_PER_HISTORICAL_ROOT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"USER_REQUEST_TOPIC","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addBlockHashLayout","inputs":[{"type":"uint256","name":"blockHashGindex","internalType":"uint256"},{"type":"tuple","name":"evidence","internalType":"struct BeaconProofVerifier.BlockHashEvidence","components":[{"type":"tuple","name":"header","internalType":"struct BeaconBlockHeader","components":[{"type":"uint64","name":"slot","internalType":"uint64"},{"type":"uint64","name":"proposerIndex","internalType":"uint64"},{"type":"bytes32","name":"parentRoot","internalType":"bytes32"},{"type":"bytes32","name":"stateRoot","internalType":"bytes32"},{"type":"bytes32","name":"bodyRoot","internalType":"bytes32"}]},{"type":"bytes32[]","name":"branch","internalType":"bytes32[]"},{"type":"tuple","name":"fork","internalType":"struct BeaconProofVerifier.ForkProof","components":[{"type":"bytes4","name":"version","internalType":"bytes4"},{"type":"bytes32[]","name":"versionBranch","internalType":"bytes32[]"},{"type":"bytes32[]","name":"genesisValidatorsRootBranch","internalType":"bytes32[]"}]}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addBlockRootsLayout","inputs":[{"type":"uint256","name":"blockRootsGindex","internalType":"uint256"},{"type":"tuple","name":"evidence","internalType":"struct BeaconProofVerifier.BlockRootsEvidence","components":[{"type":"tuple","name":"laterHeader","internalType":"struct BeaconBlockHeader","components":[{"type":"uint64","name":"slot","internalType":"uint64"},{"type":"uint64","name":"proposerIndex","internalType":"uint64"},{"type":"bytes32","name":"parentRoot","internalType":"bytes32"},{"type":"bytes32","name":"stateRoot","internalType":"bytes32"},{"type":"bytes32","name":"bodyRoot","internalType":"bytes32"}]},{"type":"uint64","name":"earlierSlotA","internalType":"uint64"},{"type":"uint64","name":"earlierSlotB","internalType":"uint64"},{"type":"bytes32[]","name":"branchA","internalType":"bytes32[]"},{"type":"bytes32[]","name":"branchB","internalType":"bytes32[]"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addHistoricalSummariesLayout","inputs":[{"type":"uint256","name":"historicalSummariesGindex","internalType":"uint256"},{"type":"tuple","name":"evidence","internalType":"struct BeaconProofVerifier.HistoricalSummariesEvidence","components":[{"type":"tuple","name":"anchorHeader","internalType":"struct BeaconBlockHeader","components":[{"type":"uint64","name":"slot","internalType":"uint64"},{"type":"uint64","name":"proposerIndex","internalType":"uint64"},{"type":"bytes32","name":"parentRoot","internalType":"bytes32"},{"type":"bytes32","name":"stateRoot","internalType":"bytes32"},{"type":"bytes32","name":"bodyRoot","internalType":"bytes32"}]},{"type":"uint64","name":"earlierSlot","internalType":"uint64"},{"type":"bytes32[]","name":"branch","internalType":"bytes32[]"}]}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"","internalType":"struct BeaconProofVerifier.SlotRange[]","components":[{"type":"uint256","name":"gindex","internalType":"uint256"},{"type":"uint64","name":"firstSlot","internalType":"uint64"},{"type":"uint64","name":"lastSlot","internalType":"uint64"}]}],"name":"bodyLayouts","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"capellaEra","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"enum MessageBridge.DeliveryStatus"}],"name":"deliveryStatus","inputs":[{"type":"bytes32","name":"id","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IDepositGate"}],"name":"depositGate","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"depositsOpen","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"destinationChainId","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"executeMessage","inputs":[{"type":"tuple","name":"proof","internalType":"struct MessageBridge.MessageProof","components":[{"type":"tuple","name":"anchorHeader","internalType":"struct BeaconBlockHeader","components":[{"type":"uint64","name":"slot","internalType":"uint64"},{"type":"uint64","name":"proposerIndex","internalType":"uint64"},{"type":"bytes32","name":"parentRoot","internalType":"bytes32"},{"type":"bytes32","name":"stateRoot","internalType":"bytes32"},{"type":"bytes32","name":"bodyRoot","internalType":"bytes32"}]},{"type":"tuple","name":"sourceHeader","internalType":"struct BeaconBlockHeader","components":[{"type":"uint64","name":"slot","internalType":"uint64"},{"type":"uint64","name":"proposerIndex","internalType":"uint64"},{"type":"bytes32","name":"parentRoot","internalType":"bytes32"},{"type":"bytes32","name":"stateRoot","internalType":"bytes32"},{"type":"bytes32","name":"bodyRoot","internalType":"bytes32"}]},{"type":"bytes32[]","name":"ancestryBranch","internalType":"bytes32[]"},{"type":"bytes32[]","name":"blockHashBranch","internalType":"bytes32[]"},{"type":"tuple","name":"sourceFork","internalType":"struct BeaconProofVerifier.ForkProof","components":[{"type":"bytes4","name":"version","internalType":"bytes4"},{"type":"bytes32[]","name":"versionBranch","internalType":"bytes32[]"},{"type":"bytes32[]","name":"genesisValidatorsRootBranch","internalType":"bytes32[]"}]},{"type":"bytes","name":"executionHeaderRlp","internalType":"bytes"},{"type":"bytes[]","name":"receiptProof","internalType":"bytes[]"},{"type":"uint256","name":"receiptIndex","internalType":"uint256"},{"type":"bytes[]","name":"transactionProof","internalType":"bytes[]"},{"type":"uint256","name":"transactionIndex","internalType":"uint256"},{"type":"uint256","name":"logIndex","internalType":"uint256"}]}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"failedMessageDataHash","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"failedMessageReceiver","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"failedMessageSender","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"","internalType":"struct BeaconProofVerifier.SlotRange[]","components":[{"type":"uint256","name":"gindex","internalType":"uint256"},{"type":"uint64","name":"firstSlot","internalType":"uint64"},{"type":"uint64","name":"lastSlot","internalType":"uint64"}]}],"name":"historicalLayouts","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IBeaconLightClient"}],"name":"lightClient","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"localChainId","inputs":[]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"maxGasPerTx","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"messageCallStatus","inputs":[{"type":"bytes32","name":"id","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"messageId","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"messageSender","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"messageSourceChainId","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"openDeposits","inputs":[{"type":"tuple","name":"proof","internalType":"struct BeaconProofVerifier.OpeningProof","components":[{"type":"uint64","name":"remoteSlot","internalType":"uint64"},{"type":"bytes","name":"remoteHeaderRlp","internalType":"bytes"},{"type":"bytes[]","name":"accountProof","internalType":"bytes[]"},{"type":"uint64","name":"storedSlot","internalType":"uint64"},{"type":"bytes[]","name":"storageProof","internalType":"bytes[]"}]}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"remoteBridge","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"remoteChainId","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"remoteLightClient","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"requireToConfirmMessage","inputs":[{"type":"address","name":"_contract","internalType":"address"},{"type":"bytes","name":"_data","internalType":"bytes"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"requireToPassMessage","inputs":[{"type":"address","name":"_contract","internalType":"address"},{"type":"bytes","name":"_data","internalType":"bytes"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"sendCutoffTimestamp","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"sourceChainId","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"","internalType":"struct BeaconProofVerifier.SlotRange[]","components":[{"type":"uint256","name":"gindex","internalType":"uint256"},{"type":"uint64","name":"firstSlot","internalType":"uint64"},{"type":"uint64","name":"lastSlot","internalType":"uint64"}]}],"name":"stateLayouts","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"transactionHash","inputs":[]}]
Contract Creation Code
0x6101a0604052348015610010575f5ffd5b5060405161296d38038061296d83398101604081905261002f91610306565b60208301516001600160a01b0380881660808190526001600160401b03851660a052911660c0526100965760405163046c82ad60e41b815260206004820152600b60248201526a1b1a59da1d10db1a595b9d60aa1b60448201526064015b60405180910390fd5b846001600160401b03165f036100df5760405163046c82ad60e41b815260206004820152600d60248201526c1c995b5bdd1950da185a5b9259609a1b604482015260640161008d565b6001600160a01b0384166101255760405163046c82ad60e41b815260206004820152600c60248201526b72656d6f746542726964676560a01b604482015260640161008d565b6001600160a01b03811661016a5760405163046c82ad60e41b815260206004820152600b60248201526a6465706f7369744761746560a81b604482015260640161008d565b60208301516001600160a01b03166101b95760405163046c82ad60e41b81526020600482015260116024820152701c995b5bdd19531a59da1d10db1a595b9d607a1b604482015260640161008d565b5f6101c346610248565b9050806001600160401b0316866001600160401b0316036101f7576040516338923c3960e01b815260040160405180910390fd5b6001600160401b0380821660e0819052878216610100526001600160a01b0380881661012052865190921661014052908316610160526102379030610278565b61018052506103cd95505050505050565b5f6001600160401b038211156102745760405163bd6eedbd60e01b81526004810183905260240161008d565b5090565b5f600160401b600160e01b035f1b83836040516020016102af92919091825260601b6001600160601b031916602082015260340190565b60408051808303601f19018152919052805160209091012016600560f01b179392505050565b80516001600160a01b03811681146102eb575f5ffd5b919050565b80516001600160401b03811681146102eb575f5ffd5b5f5f5f5f5f5f86880360e081121561031c575f5ffd5b610325886102d5565b9650610333602089016102f0565b9550610341604089016102d5565b94506040605f1982011215610354575f5ffd5b50604080519081016001600160401b038111828210171561038357634e487b7160e01b5f52604160045260245ffd5b604052610392606089016102f0565b81526103a0608089016102d5565b602082015292506103b360a088016102f0565b91506103c160c088016102d5565b90509295509295509295565b60805160a05160c05160e051610100516101205161014051610160516101805161249a6104d35f395f6113c801525f8181610501015261135401525f8181610211015281816112560152818161128101526112c901525f81816104280152610dbf01525f81816103c701528181610528015281816107cf015281816110510152818161109f015261143b01525f81816102a301528181610331015281816110d601528181611124015261141301525f81816102550152610c8d01525f818161056a01528181610971015261150701525f81816103f90152818161094f01528181610a0c01528181610ae201528181610b19015281816114e5015261159a015261249a5ff3fe608060405234801561000f575f5ffd5b5060043610610208575f3560e01c8063b07506111161011f578063dc8601b3116100a9578063e671a22611610079578063e671a226146104fc578063e951819614610523578063e9c749c11461054a578063ebcea59d14610552578063f2691ed214610565575f5ffd5b8063dc8601b3146104be578063dea0192a146104d1578063e37c3289146104e4578063e5789d03146104f2575f5ffd5b8063cb08a10c116100ef578063cb08a10c1461044a578063cda30f3a1461045d578063d0055fca14610465578063d36e1cc314610494578063d67bdd25146104a7575f5ffd5b8063b0750611146103c5578063b5700e68146103f4578063be3365c51461041b578063c97123bb14610423575f5ffd5b8063549c4627116101a0578063669f618b11610170578063669f618b1461036657806394643f711461036e5780639e307dff14610381578063aca6a56a14610389578063ae5ce9091461039e575f5ffd5b8063549c46271461030157806359e7b431146103245780635b056da51461032c57806363f08d5e14610353575f5ffd5b806317ca05aa116101db57806317ca05aa146102d05780633f9a8e7e146102e557806349939d18146102f85780634a610b04146102e5575f5ffd5b8063023118101461020c57806306c7d543146102505780630ac1c3131461028f5780631544298e146102a1575b5f5ffd5b6102337f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160401b0390911681526020015b60405180910390f35b6102777f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610247565b6002545b604051908152602001610247565b7f00000000000000000000000000000000000000000000000000000000000000006001600160401b0316610293565b6102e36102de36600461190a565b61058c565b005b6102776102f3366004611947565b505f90565b61023361200081565b5f5461031490600160401b900460ff1681565b6040519015158152602001610247565b610293601881565b6102337f000000000000000000000000000000000000000000000000000000000000000081565b6102e361036136600461195e565b61062a565b600154610293565b61029361037c366004611995565b61079f565b6102936107b6565b6103916107f2565b6040516102479190611a25565b6102937f482515ce3d9494a37ce83f18b72b363449458435fafdd7a53ddea7460fe01b5881565b7f00000000000000000000000000000000000000000000000000000000000000006001600160401b0316610293565b6102777f000000000000000000000000000000000000000000000000000000000000000081565b61039161087a565b6102777f000000000000000000000000000000000000000000000000000000000000000081565b610314610458366004611947565b6108f1565b610293600d81565b610487610473366004611947565b5f9081526003602052604090205460ff1690565b6040516102479190611aa9565b6102e36104a2366004611ae5565b61091d565b5f54600160481b90046001600160a01b0316610277565b6102936104cc366004611995565b6109cd565b6102e36104df366004611b28565b6109da565b6102936102f3366004611947565b63ffffffff610293565b6102777f000000000000000000000000000000000000000000000000000000000000000081565b6102337f000000000000000000000000000000000000000000000000000000000000000081565b610391610a37565b6102e3610560366004611ae5565b610ab1565b6102337f000000000000000000000000000000000000000000000000000000000000000081565b5f54600160401b900460ff16156105a05750565b5f6105aa82610b0e565b5f805468ff00000000000000001916600160401b1790559050806105d16020840184611b88565b6001600160401b03167fecf255cbc510c2c1c539f1ab585c3e9c74c3a802e9da8c20aba9378bebffcb3f61060b6080860160608701611b88565b6040516001600160401b03909116815260200160405180910390a35050565b6001541561065957600154604051628ba8d760e61b815260040161065091815260200190565b60405180910390fd5b806102200135816101e001351461069557604051634dd1399960e01b81526101e082013560048201526102208201356024820152604401610650565b5f5f5f6106a184610d01565b9250925092505f5f6106b285610e71565b915091506106c08285610fe5565b81515f9081526003602052604081205460ff1660028111156106e4576106e4611a95565b146107085781516040516356bc34a160e01b81526004810191909152602401610650565b81515f908152600360205260409020805460ff1916600117905561072d8282856111a3565b81515f90815260036020908152604091829020805460ff191660021790558351828501518286015193516001815291936001600160a01b03918216939116917fe194ef610f9150a2db4110b3db5116fd623175dca3528d7ae7046a1042f84fe7910160405180910390a4505050505050565b5f6107ad8585856080611222565b95945050505050565b6001545f906107c457505f90565b506001600160401b037f00000000000000000000000000000000000000000000000000000000000000001690565b60606004600101805480602002602001604051908101604052809291908181526020015f905b82821015610871575f8481526020908190206040805160608101825260028602909201805483526001908101546001600160401b0380821685870152600160401b90910416918301919091529083529092019101610818565b50505050905090565b606060048054604080516020808402820181019092528281529291905f9084018215610871575f8481526020908190206040805160608101825260028602909201805483526001908101546001600160401b0380821685870152600160401b90910416918301919091529083529092019101610818565b5f60025f8381526003602052604090205460ff16600281111561091657610916611a95565b1492915050565b60405163393d7fe560e21b815273b8b1b2c701aff6bfc4538a958dd58abc4dea4eb69063e4f5ff949061099d906006907f0000000000000000000000000000000000000000000000000000000000000000907f00000000000000000000000000000000000000000000000000000000000000009088908890600401611c69565b5f6040518083038186803b1580156109b3575f5ffd5b505af41580156109c5573d5f5f3e3d5ffd5b505050505050565b5f6107ad8585855f611222565b604051638253721d60e01b815273b8b1b2c701aff6bfc4538a958dd58abc4dea4eb690638253721d9061099d906004907f000000000000000000000000000000000000000000000000000000000000000090879087908401611cf3565b606060046002018054604080516020808402820181019092528281529291905f9084018215610871575f8481526020908190206040805160608101825260028602909201805483526001908101546001600160401b0380821685870152600160401b90910416918301919091529083529092019101610818565b604051627e99bf60e61b815273b8b1b2c701aff6bfc4538a958dd58abc4dea4eb690631fa66fc09061099d906005907f00000000000000000000000000000000000000000000000000000000000000009087908790600401611e11565b5f6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000166395c51820610b4b6020850185611b88565b6040516001600160e01b031960e084901b1681526001600160401b039091166004820152602401602060405180830381865afa158015610b8d573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610bb19190611ea2565b905080610bea57610bc56020830183611b88565b60405163b183785d60e01b81526001600160401b039091166004820152602401610650565b5f610bf86020840184611eb9565b604051610c06929190611f09565b60405180910390209050818114610c3a5760405163c0bf24ab60e01b81526004810183905260248101829052604401610650565b73b3d7d5d954b3ddb01b7020c34b669ac118113427637acc048b610c616020860186611eb9565b610c6e6040880188611f18565b610c7e60808a0160608b01611b88565b610c8b60808b018b611f18565b7f00000000000000000000000000000000000000000000000000000000000000006040518963ffffffff1660e01b8152600401610ccf989796959493929190612019565b5f6040518083038186803b158015610ce5575f5ffd5b505af4158015610cf7573d5f5f3e3d5ffd5b5050505050919050565b60605f80610d208460a08101610d1b610140830183611f18565b6114b3565b610d6d610d316101a0860186611eb9565b604051610d3f929190611f09565b60405190819003902060a08601610d5a610160880188611f18565b610d686101808a018a612081565b611568565b735a5ff919270c2776cbf6db3f13228267938466ae63b29b36f2610d956101a0870187611eb9565b610da36101c0890189611f18565b6101e08a0135610db76102008c018c611f18565b8c61024001357f00000000000000000000000000000000000000000000000000000000000000007f482515ce3d9494a37ce83f18b72b363449458435fafdd7a53ddea7460fe01b586040518b63ffffffff1660e01b8152600401610e249a9998979695949392919061209f565b5f60405180830381865af4158015610e3e573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610e659190810190612142565b90969195509350915050565b6040805160e0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c08101919091526060604f83511015610ece57604051630b284dcd60e11b815260040160405180910390fd5b5f5f60208501518452604085015160601c6020850152605485015160601c6040850152606885015160e01c6060850152606c8501515f1a9150606d8501515f1a9050606e8501515f1a6080850152815f1480610f2a5750602082115b80610f33575080155b80610f3e5750602081115b15610f5c57604051630b284dcd60e11b815260040160405180910390fd5b5f81610f6984604f612219565b610f739190612219565b90508086511015610f9757604051630b284dcd60e11b815260040160405180910390fd5b5f610fa384604f612219565b9050604f6020018701518460031b610100031c60a0870152806020018701518360031b610100031c60c0870152610fda87836115ff565b945050505050915091565b815181146110135781516040516378f1773b60e11b8152610650918391600401918252602082015260400190565b815161102c906001600160e01b031916600560f01b1490565b61104f5781516040516315c9916d60e31b81526004810191909152602401610650565b7f00000000000000000000000000000000000000000000000000000000000000006001600160401b03168260a00151146110d45760a082015160405163663ba88960e01b81526001600160401b037f00000000000000000000000000000000000000000000000000000000000000001660048201526024810191909152604401610650565b7f00000000000000000000000000000000000000000000000000000000000000006001600160401b03168260c00151146111595760c082015160405163dec7288b60e01b81526001600160401b037f00000000000000000000000000000000000000000000000000000000000000001660048201526024810191909152604401610650565b608082015160ff1615801590611176575060808281015160ff1614155b1561119f576080820151604051631c54f4a960e21b815260ff9091166004820152602401610650565b5050565b6020808401515f80546001600160a01b03909216600160481b02600160481b600160e81b03199092169190911781558451600155600283905560408501518451909282918291870182865af19050806112015784516112019061168f565b50505f8054600160481b600160e81b03191681556001819055600255505050565b5f8054600160401b900460ff1661124c57604051630420120760e51b815260040160405180910390fd5b6001600160401b037f000000000000000000000000000000000000000000000000000000000000000016158015906112ad57507f00000000000000000000000000000000000000000000000000000000000000006001600160401b03164210155b156112f65760405163575361eb60e11b81526001600160401b037f0000000000000000000000000000000000000000000000000000000000000000166004820152602401610650565b61130084846116be565b5f546001600160401b0316611316816001612232565b5f805467ffffffffffffffff19166001600160401b039290921691909117815560405163eafbed0760e01b81526020600482015260248101919091527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063eafbed07906044015f604051808303815f87803b15801561139d575f5ffd5b505af11580156113af573d5f5f3e3d5ffd5b50506040805160e0810182526001600160401b038581167f0000000000000000000000000000000000000000000000000000000000000000178083523360208401526001600160a01b038c16938301939093525f606083015260ff881660808301527f0000000000000000000000000000000000000000000000000000000000000000811660a08301527f00000000000000000000000000000000000000000000000000000000000000001660c082015290945091508390507f482515ce3d9494a37ce83f18b72b363449458435fafdd7a53ddea7460fe01b58611494838989611793565b6040516114a19190612251565b60405180910390a25050949350505050565b6040516378865b7160e11b815273b8b1b2c701aff6bfc4538a958dd58abc4dea4eb69063f10cb6e290611536906004907f0000000000000000000000000000000000000000000000000000000000000000907f0000000000000000000000000000000000000000000000000000000000000000908a908a908a908a908701612283565b5f6040518083038186803b15801561154c575f5ffd5b505af415801561155e573d5f5f3e3d5ffd5b5050505050505050565b604051632b6c90fb60e11b815273b8b1b2c701aff6bfc4538a958dd58abc4dea4eb6906356d921f6906115cc906005907f0000000000000000000000000000000000000000000000000000000000000000908a908a908a908a908a906004016122d8565b5f6040518083038186803b1580156115e2575f5ffd5b505af41580156115f4573d5f5f3e3d5ffd5b505050505050505050565b60605f82845161160f9190612338565b9050806001600160401b038111156116295761162961210c565b6040519080825280601f01601f191660200182016040528015611653576020820181803683370190505b5091505f81602084018386602089010160045afa90508061168757604051630b284dcd60e11b815260040160405180910390fd5b505092915050565b3d80156116a157604051815f823e8181fd5b50604051637ca7f96d60e01b815260048101829052602401610650565b60048110156116cb575050565b5f6116d9600482848661234b565b6116e291612372565b90506001600160e01b0319811663a9059cbb60e01b148061171357506001600160e01b0319811663095ea7b360e01b145b8061172e57506001600160e01b031981166323b872dd60e01b145b8061174957506001600160e01b03198116630200057560e51b145b8061176457506001600160e01b0319811663cae9ca5160e01b145b1561178e576040516327fe336560e21b81526001600160e01b031982166004820152602401610650565b505050565b60605f6117a38560a00151611821565b90505f6117b38660c00151611821565b9050855f015186602001518760400151886060015185858b608001516117dd8d60a001518a61185c565b6117eb8e60c001518a61185c565b8d8d6040516020016118079b9a999897969594939291906123c3565b604051602081830303815290604052925050509392505050565b60015b602081108015611840575061183a816008612457565b82901c15155b15611857578061184f8161246e565b915050611824565b919050565b6060816001600160401b038111156118765761187661210c565b6040519080825280601f01601f1916602001820160405280156118a0576020820181803683370190505b5090505f5b82811015611903576118b8816008612457565b84901c60f81b82826118cb600187612338565b6118d59190612338565b815181106118e5576118e5612486565b60200101906001600160f81b03191690815f1a9053506001016118a5565b5092915050565b5f6020828403121561191a575f5ffd5b81356001600160401b0381111561192f575f5ffd5b820160a08185031215611940575f5ffd5b9392505050565b5f60208284031215611957575f5ffd5b5035919050565b5f6020828403121561196e575f5ffd5b81356001600160401b03811115611983575f5ffd5b82016102608185031215611940575f5ffd5b5f5f5f5f606085870312156119a8575f5ffd5b84356001600160a01b03811681146119be575f5ffd5b935060208501356001600160401b038111156119d8575f5ffd5b8501601f810187136119e8575f5ffd5b80356001600160401b038111156119fd575f5ffd5b876020828401011115611a0e575f5ffd5b949760209190910196509394604001359392505050565b602080825282518282018190525f918401906040840190835b81811015611a8a578351805184526001600160401b0360208201511660208501526001600160401b03604082015116604085015250606083019250602084019350600181019050611a3e565b509095945050505050565b634e487b7160e01b5f52602160045260245ffd5b6020810160038310611ac957634e487b7160e01b5f52602160045260245ffd5b91905290565b5f60e08284031215611adf575f5ffd5b50919050565b5f5f60408385031215611af6575f5ffd5b8235915060208301356001600160401b03811115611b12575f5ffd5b611b1e85828601611acf565b9150509250929050565b5f5f60408385031215611b39575f5ffd5b8235915060208301356001600160401b03811115611b55575f5ffd5b83016101208186031215611b67575f5ffd5b809150509250929050565b80356001600160401b0381168114611857575f5ffd5b5f60208284031215611b98575f5ffd5b61194082611b72565b6001600160401b03611bb282611b72565b1682526001600160401b03611bc960208301611b72565b1660208301526040818101359083015260608082013590830152608090810135910152565b5f5f8335601e19843603018112611c03575f5ffd5b83016020810192503590506001600160401b03811115611c21575f5ffd5b8060051b3603821315611c32575f5ffd5b9250929050565b8183525f6001600160fb1b03831115611c50575f5ffd5b8260051b80836020870137939093016020019392505050565b8581526001600160a01b03851660208201526001600160401b03841660408201526060810183905260a060808201819052611ca690820183611ba1565b6001600160401b03611cba60a08401611b72565b166101408201525f611ccf60c0840184611bee565b60e0610160850152611ce661018085018284611c39565b9998505050505050505050565b8481526001600160a01b038416602082015260408101839052608060608201819052611d2190820183611ba1565b6001600160401b03611d3560a08401611b72565b166101208201526001600160401b03611d5060c08401611b72565b166101408201525f611d6560e0840184611bee565b610120610160850152611d7d6101a085018284611c39565b915050611d8e610100850185611bee565b848303607f1901610180860152611ce6838284611c39565b5f81356001600160e01b03198116808214611dbf575f5ffd5b845250611dcf6020830183611bee565b60606020860152611de4606086018284611c39565b915050611df46040840184611bee565b8583036040870152611e07838284611c39565b9695505050505050565b8481526001600160a01b038416602082015260408101839052608060608201819052611e3f90820183611ba1565b5f611e4d60a0840184611bee565b60e0610120850152611e6461016085018284611c39565b91505060c0840135605e19853603018112611e7d575f5ffd5b838203607f1901610140850152611e9682828701611da6565b98975050505050505050565b5f60208284031215611eb2575f5ffd5b5051919050565b5f5f8335601e19843603018112611ece575f5ffd5b8301803591506001600160401b03821115611ee7575f5ffd5b602001915036819003821315611c32575f5ffd5b81818437505f910190815290565b818382375f9101908152919050565b5f5f8335601e19843603018112611f2d575f5ffd5b8301803591506001600160401b03821115611f46575f5ffd5b6020019150600581901b3603821315611c32575f5ffd5b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b5f8383855260208501945060208460051b820101835f5b8681101561200d57838303601f19018852813536879003601e19018112611fc1575f5ffd5b86016020810190356001600160401b03811115611fdc575f5ffd5b803603821315611fea575f5ffd5b611ff5858284611f5d565b60209a8b019a90955093909301925050600101611f9c565b50909695505050505050565b60a081525f61202c60a083018a8c611f5d565b828103602084015261203f81898b611f85565b90506001600160401b03871660408401528281036060840152612063818688611f85565b91505060018060a01b03831660808301529998505050505050505050565b5f8235605e19833603018112612095575f5ffd5b9190910192915050565b60e081525f6120b260e083018c8e611f5d565b82810360208401526120c5818b8d611f85565b905088604084015282810360608401526120e081888a611f85565b608084019690965250506001600160a01b039290921660a083015260c090910152979650505050505050565b634e487b7160e01b5f52604160045260245ffd5b5f5b8381101561213a578181015183820152602001612122565b50505f910152565b5f5f5f60608486031215612154575f5ffd5b835160208501519093506001600160401b03811115612171575f5ffd5b8401601f81018613612181575f5ffd5b80516001600160401b0381111561219a5761219a61210c565b604051601f8201601f19908116603f011681016001600160401b03811182821017156121c8576121c861210c565b6040528181528282016020018810156121df575f5ffd5b6121f0826020830160208601612120565b60409690960151949795965093949350505050565b634e487b7160e01b5f52601160045260245ffd5b8082018082111561222c5761222c612205565b92915050565b6001600160401b03818116838216019081111561222c5761222c612205565b602081525f825180602084015261226f816040850160208701612120565b601f01601f19169190910160400192915050565b8781526001600160a01b03871660208201526001600160401b03861660408201526122b16060820186611ba1565b6122bf610100820185611ba1565b6101c06101a08201525f611ce66101c083018486611c39565b8781526001600160a01b0387166020820152604081018690526122fe6060820186611ba1565b6101406101008201525f61231761014083018587611c39565b82810361012084015261232a8185611da6565b9a9950505050505050505050565b8181038181111561222c5761222c612205565b5f5f85851115612359575f5ffd5b83861115612365575f5ffd5b5050820193919092039150565b80356001600160e01b03198116906004841015611903576001600160e01b031960049490940360031b84901b1690921692915050565b5f81516123b9818560208601612120565b9290920192915050565b8b81526bffffffffffffffffffffffff1960608c811b821660208401528b901b1660348201526001600160e01b031960e08a901b1660488201526001600160f81b031960f889811b8216604c84015288811b8216604d84015287901b16604e8201525f61244661243f612439604f8501896123a8565b876123a8565b8486611efb565b9d9c50505050505050505050505050565b808202811582820484141761222c5761222c612205565b5f6001820161247f5761247f612205565b5060010190565b634e487b7160e01b5f52603260045260245ffd0000000000000000000000001dbbcc0bc25de5f6ae122fb0009b3ee4931fd9580000000000000000000000000000000000000000000000000000000000aa36a7000000000000000000000000071da4d1b038787c16dae145a8b8c1edb2470f51000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064ddc23ff43ea0cd2ce9a13ef6681ee651e76e4e00000000000000000000000000000000000000000000000000000000000000de00000000000000000000000085fbe4c5f7992fbd97a8e4dafc821fad3b0d20f3
Deployed ByteCode
0x608060405234801561000f575f5ffd5b5060043610610208575f3560e01c8063b07506111161011f578063dc8601b3116100a9578063e671a22611610079578063e671a226146104fc578063e951819614610523578063e9c749c11461054a578063ebcea59d14610552578063f2691ed214610565575f5ffd5b8063dc8601b3146104be578063dea0192a146104d1578063e37c3289146104e4578063e5789d03146104f2575f5ffd5b8063cb08a10c116100ef578063cb08a10c1461044a578063cda30f3a1461045d578063d0055fca14610465578063d36e1cc314610494578063d67bdd25146104a7575f5ffd5b8063b0750611146103c5578063b5700e68146103f4578063be3365c51461041b578063c97123bb14610423575f5ffd5b8063549c4627116101a0578063669f618b11610170578063669f618b1461036657806394643f711461036e5780639e307dff14610381578063aca6a56a14610389578063ae5ce9091461039e575f5ffd5b8063549c46271461030157806359e7b431146103245780635b056da51461032c57806363f08d5e14610353575f5ffd5b806317ca05aa116101db57806317ca05aa146102d05780633f9a8e7e146102e557806349939d18146102f85780634a610b04146102e5575f5ffd5b8063023118101461020c57806306c7d543146102505780630ac1c3131461028f5780631544298e146102a1575b5f5ffd5b6102337f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160401b0390911681526020015b60405180910390f35b6102777f00000000000000000000000064ddc23ff43ea0cd2ce9a13ef6681ee651e76e4e81565b6040516001600160a01b039091168152602001610247565b6002545b604051908152602001610247565b7f00000000000000000000000000000000000000000000000000000000000003af6001600160401b0316610293565b6102e36102de36600461190a565b61058c565b005b6102776102f3366004611947565b505f90565b61023361200081565b5f5461031490600160401b900460ff1681565b6040519015158152602001610247565b610293601881565b6102337f00000000000000000000000000000000000000000000000000000000000003af81565b6102e361036136600461195e565b61062a565b600154610293565b61029361037c366004611995565b61079f565b6102936107b6565b6103916107f2565b6040516102479190611a25565b6102937f482515ce3d9494a37ce83f18b72b363449458435fafdd7a53ddea7460fe01b5881565b7f0000000000000000000000000000000000000000000000000000000000aa36a76001600160401b0316610293565b6102777f0000000000000000000000001dbbcc0bc25de5f6ae122fb0009b3ee4931fd95881565b61039161087a565b6102777f000000000000000000000000071da4d1b038787c16dae145a8b8c1edb2470f5181565b610314610458366004611947565b6108f1565b610293600d81565b610487610473366004611947565b5f9081526003602052604090205460ff1690565b6040516102479190611aa9565b6102e36104a2366004611ae5565b61091d565b5f54600160481b90046001600160a01b0316610277565b6102936104cc366004611995565b6109cd565b6102e36104df366004611b28565b6109da565b6102936102f3366004611947565b63ffffffff610293565b6102777f00000000000000000000000085fbe4c5f7992fbd97a8e4dafc821fad3b0d20f381565b6102337f0000000000000000000000000000000000000000000000000000000000aa36a781565b610391610a37565b6102e3610560366004611ae5565b610ab1565b6102337f00000000000000000000000000000000000000000000000000000000000000de81565b5f54600160401b900460ff16156105a05750565b5f6105aa82610b0e565b5f805468ff00000000000000001916600160401b1790559050806105d16020840184611b88565b6001600160401b03167fecf255cbc510c2c1c539f1ab585c3e9c74c3a802e9da8c20aba9378bebffcb3f61060b6080860160608701611b88565b6040516001600160401b03909116815260200160405180910390a35050565b6001541561065957600154604051628ba8d760e61b815260040161065091815260200190565b60405180910390fd5b806102200135816101e001351461069557604051634dd1399960e01b81526101e082013560048201526102208201356024820152604401610650565b5f5f5f6106a184610d01565b9250925092505f5f6106b285610e71565b915091506106c08285610fe5565b81515f9081526003602052604081205460ff1660028111156106e4576106e4611a95565b146107085781516040516356bc34a160e01b81526004810191909152602401610650565b81515f908152600360205260409020805460ff1916600117905561072d8282856111a3565b81515f90815260036020908152604091829020805460ff191660021790558351828501518286015193516001815291936001600160a01b03918216939116917fe194ef610f9150a2db4110b3db5116fd623175dca3528d7ae7046a1042f84fe7910160405180910390a4505050505050565b5f6107ad8585856080611222565b95945050505050565b6001545f906107c457505f90565b506001600160401b037f0000000000000000000000000000000000000000000000000000000000aa36a71690565b60606004600101805480602002602001604051908101604052809291908181526020015f905b82821015610871575f8481526020908190206040805160608101825260028602909201805483526001908101546001600160401b0380821685870152600160401b90910416918301919091529083529092019101610818565b50505050905090565b606060048054604080516020808402820181019092528281529291905f9084018215610871575f8481526020908190206040805160608101825260028602909201805483526001908101546001600160401b0380821685870152600160401b90910416918301919091529083529092019101610818565b5f60025f8381526003602052604090205460ff16600281111561091657610916611a95565b1492915050565b60405163393d7fe560e21b815273b8b1b2c701aff6bfc4538a958dd58abc4dea4eb69063e4f5ff949061099d906006907f0000000000000000000000001dbbcc0bc25de5f6ae122fb0009b3ee4931fd958907f00000000000000000000000000000000000000000000000000000000000000de9088908890600401611c69565b5f6040518083038186803b1580156109b3575f5ffd5b505af41580156109c5573d5f5f3e3d5ffd5b505050505050565b5f6107ad8585855f611222565b604051638253721d60e01b815273b8b1b2c701aff6bfc4538a958dd58abc4dea4eb690638253721d9061099d906004907f0000000000000000000000001dbbcc0bc25de5f6ae122fb0009b3ee4931fd95890879087908401611cf3565b606060046002018054604080516020808402820181019092528281529291905f9084018215610871575f8481526020908190206040805160608101825260028602909201805483526001908101546001600160401b0380821685870152600160401b90910416918301919091529083529092019101610818565b604051627e99bf60e61b815273b8b1b2c701aff6bfc4538a958dd58abc4dea4eb690631fa66fc09061099d906005907f0000000000000000000000001dbbcc0bc25de5f6ae122fb0009b3ee4931fd9589087908790600401611e11565b5f6001600160a01b037f0000000000000000000000001dbbcc0bc25de5f6ae122fb0009b3ee4931fd958166395c51820610b4b6020850185611b88565b6040516001600160e01b031960e084901b1681526001600160401b039091166004820152602401602060405180830381865afa158015610b8d573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610bb19190611ea2565b905080610bea57610bc56020830183611b88565b60405163b183785d60e01b81526001600160401b039091166004820152602401610650565b5f610bf86020840184611eb9565b604051610c06929190611f09565b60405180910390209050818114610c3a5760405163c0bf24ab60e01b81526004810183905260248101829052604401610650565b73b3d7d5d954b3ddb01b7020c34b669ac118113427637acc048b610c616020860186611eb9565b610c6e6040880188611f18565b610c7e60808a0160608b01611b88565b610c8b60808b018b611f18565b7f00000000000000000000000064ddc23ff43ea0cd2ce9a13ef6681ee651e76e4e6040518963ffffffff1660e01b8152600401610ccf989796959493929190612019565b5f6040518083038186803b158015610ce5575f5ffd5b505af4158015610cf7573d5f5f3e3d5ffd5b5050505050919050565b60605f80610d208460a08101610d1b610140830183611f18565b6114b3565b610d6d610d316101a0860186611eb9565b604051610d3f929190611f09565b60405190819003902060a08601610d5a610160880188611f18565b610d686101808a018a612081565b611568565b735a5ff919270c2776cbf6db3f13228267938466ae63b29b36f2610d956101a0870187611eb9565b610da36101c0890189611f18565b6101e08a0135610db76102008c018c611f18565b8c61024001357f000000000000000000000000071da4d1b038787c16dae145a8b8c1edb2470f517f482515ce3d9494a37ce83f18b72b363449458435fafdd7a53ddea7460fe01b586040518b63ffffffff1660e01b8152600401610e249a9998979695949392919061209f565b5f60405180830381865af4158015610e3e573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610e659190810190612142565b90969195509350915050565b6040805160e0810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c08101919091526060604f83511015610ece57604051630b284dcd60e11b815260040160405180910390fd5b5f5f60208501518452604085015160601c6020850152605485015160601c6040850152606885015160e01c6060850152606c8501515f1a9150606d8501515f1a9050606e8501515f1a6080850152815f1480610f2a5750602082115b80610f33575080155b80610f3e5750602081115b15610f5c57604051630b284dcd60e11b815260040160405180910390fd5b5f81610f6984604f612219565b610f739190612219565b90508086511015610f9757604051630b284dcd60e11b815260040160405180910390fd5b5f610fa384604f612219565b9050604f6020018701518460031b610100031c60a0870152806020018701518360031b610100031c60c0870152610fda87836115ff565b945050505050915091565b815181146110135781516040516378f1773b60e11b8152610650918391600401918252602082015260400190565b815161102c906001600160e01b031916600560f01b1490565b61104f5781516040516315c9916d60e31b81526004810191909152602401610650565b7f0000000000000000000000000000000000000000000000000000000000aa36a76001600160401b03168260a00151146110d45760a082015160405163663ba88960e01b81526001600160401b037f0000000000000000000000000000000000000000000000000000000000aa36a71660048201526024810191909152604401610650565b7f00000000000000000000000000000000000000000000000000000000000003af6001600160401b03168260c00151146111595760c082015160405163dec7288b60e01b81526001600160401b037f00000000000000000000000000000000000000000000000000000000000003af1660048201526024810191909152604401610650565b608082015160ff1615801590611176575060808281015160ff1614155b1561119f576080820151604051631c54f4a960e21b815260ff9091166004820152602401610650565b5050565b6020808401515f80546001600160a01b03909216600160481b02600160481b600160e81b03199092169190911781558451600155600283905560408501518451909282918291870182865af19050806112015784516112019061168f565b50505f8054600160481b600160e81b03191681556001819055600255505050565b5f8054600160401b900460ff1661124c57604051630420120760e51b815260040160405180910390fd5b6001600160401b037f000000000000000000000000000000000000000000000000000000000000000016158015906112ad57507f00000000000000000000000000000000000000000000000000000000000000006001600160401b03164210155b156112f65760405163575361eb60e11b81526001600160401b037f0000000000000000000000000000000000000000000000000000000000000000166004820152602401610650565b61130084846116be565b5f546001600160401b0316611316816001612232565b5f805467ffffffffffffffff19166001600160401b039290921691909117815560405163eafbed0760e01b81526020600482015260248101919091527f00000000000000000000000085fbe4c5f7992fbd97a8e4dafc821fad3b0d20f36001600160a01b03169063eafbed07906044015f604051808303815f87803b15801561139d575f5ffd5b505af11580156113af573d5f5f3e3d5ffd5b50506040805160e0810182526001600160401b038581167f000500009abe8a276baabaab63c118b021bc21cc5970732a0000000000000000178083523360208401526001600160a01b038c16938301939093525f606083015260ff881660808301527f00000000000000000000000000000000000000000000000000000000000003af811660a08301527f0000000000000000000000000000000000000000000000000000000000aa36a71660c082015290945091508390507f482515ce3d9494a37ce83f18b72b363449458435fafdd7a53ddea7460fe01b58611494838989611793565b6040516114a19190612251565b60405180910390a25050949350505050565b6040516378865b7160e11b815273b8b1b2c701aff6bfc4538a958dd58abc4dea4eb69063f10cb6e290611536906004907f0000000000000000000000001dbbcc0bc25de5f6ae122fb0009b3ee4931fd958907f00000000000000000000000000000000000000000000000000000000000000de908a908a908a908a908701612283565b5f6040518083038186803b15801561154c575f5ffd5b505af415801561155e573d5f5f3e3d5ffd5b5050505050505050565b604051632b6c90fb60e11b815273b8b1b2c701aff6bfc4538a958dd58abc4dea4eb6906356d921f6906115cc906005907f0000000000000000000000001dbbcc0bc25de5f6ae122fb0009b3ee4931fd958908a908a908a908a908a906004016122d8565b5f6040518083038186803b1580156115e2575f5ffd5b505af41580156115f4573d5f5f3e3d5ffd5b505050505050505050565b60605f82845161160f9190612338565b9050806001600160401b038111156116295761162961210c565b6040519080825280601f01601f191660200182016040528015611653576020820181803683370190505b5091505f81602084018386602089010160045afa90508061168757604051630b284dcd60e11b815260040160405180910390fd5b505092915050565b3d80156116a157604051815f823e8181fd5b50604051637ca7f96d60e01b815260048101829052602401610650565b60048110156116cb575050565b5f6116d9600482848661234b565b6116e291612372565b90506001600160e01b0319811663a9059cbb60e01b148061171357506001600160e01b0319811663095ea7b360e01b145b8061172e57506001600160e01b031981166323b872dd60e01b145b8061174957506001600160e01b03198116630200057560e51b145b8061176457506001600160e01b0319811663cae9ca5160e01b145b1561178e576040516327fe336560e21b81526001600160e01b031982166004820152602401610650565b505050565b60605f6117a38560a00151611821565b90505f6117b38660c00151611821565b9050855f015186602001518760400151886060015185858b608001516117dd8d60a001518a61185c565b6117eb8e60c001518a61185c565b8d8d6040516020016118079b9a999897969594939291906123c3565b604051602081830303815290604052925050509392505050565b60015b602081108015611840575061183a816008612457565b82901c15155b15611857578061184f8161246e565b915050611824565b919050565b6060816001600160401b038111156118765761187661210c565b6040519080825280601f01601f1916602001820160405280156118a0576020820181803683370190505b5090505f5b82811015611903576118b8816008612457565b84901c60f81b82826118cb600187612338565b6118d59190612338565b815181106118e5576118e5612486565b60200101906001600160f81b03191690815f1a9053506001016118a5565b5092915050565b5f6020828403121561191a575f5ffd5b81356001600160401b0381111561192f575f5ffd5b820160a08185031215611940575f5ffd5b9392505050565b5f60208284031215611957575f5ffd5b5035919050565b5f6020828403121561196e575f5ffd5b81356001600160401b03811115611983575f5ffd5b82016102608185031215611940575f5ffd5b5f5f5f5f606085870312156119a8575f5ffd5b84356001600160a01b03811681146119be575f5ffd5b935060208501356001600160401b038111156119d8575f5ffd5b8501601f810187136119e8575f5ffd5b80356001600160401b038111156119fd575f5ffd5b876020828401011115611a0e575f5ffd5b949760209190910196509394604001359392505050565b602080825282518282018190525f918401906040840190835b81811015611a8a578351805184526001600160401b0360208201511660208501526001600160401b03604082015116604085015250606083019250602084019350600181019050611a3e565b509095945050505050565b634e487b7160e01b5f52602160045260245ffd5b6020810160038310611ac957634e487b7160e01b5f52602160045260245ffd5b91905290565b5f60e08284031215611adf575f5ffd5b50919050565b5f5f60408385031215611af6575f5ffd5b8235915060208301356001600160401b03811115611b12575f5ffd5b611b1e85828601611acf565b9150509250929050565b5f5f60408385031215611b39575f5ffd5b8235915060208301356001600160401b03811115611b55575f5ffd5b83016101208186031215611b67575f5ffd5b809150509250929050565b80356001600160401b0381168114611857575f5ffd5b5f60208284031215611b98575f5ffd5b61194082611b72565b6001600160401b03611bb282611b72565b1682526001600160401b03611bc960208301611b72565b1660208301526040818101359083015260608082013590830152608090810135910152565b5f5f8335601e19843603018112611c03575f5ffd5b83016020810192503590506001600160401b03811115611c21575f5ffd5b8060051b3603821315611c32575f5ffd5b9250929050565b8183525f6001600160fb1b03831115611c50575f5ffd5b8260051b80836020870137939093016020019392505050565b8581526001600160a01b03851660208201526001600160401b03841660408201526060810183905260a060808201819052611ca690820183611ba1565b6001600160401b03611cba60a08401611b72565b166101408201525f611ccf60c0840184611bee565b60e0610160850152611ce661018085018284611c39565b9998505050505050505050565b8481526001600160a01b038416602082015260408101839052608060608201819052611d2190820183611ba1565b6001600160401b03611d3560a08401611b72565b166101208201526001600160401b03611d5060c08401611b72565b166101408201525f611d6560e0840184611bee565b610120610160850152611d7d6101a085018284611c39565b915050611d8e610100850185611bee565b848303607f1901610180860152611ce6838284611c39565b5f81356001600160e01b03198116808214611dbf575f5ffd5b845250611dcf6020830183611bee565b60606020860152611de4606086018284611c39565b915050611df46040840184611bee565b8583036040870152611e07838284611c39565b9695505050505050565b8481526001600160a01b038416602082015260408101839052608060608201819052611e3f90820183611ba1565b5f611e4d60a0840184611bee565b60e0610120850152611e6461016085018284611c39565b91505060c0840135605e19853603018112611e7d575f5ffd5b838203607f1901610140850152611e9682828701611da6565b98975050505050505050565b5f60208284031215611eb2575f5ffd5b5051919050565b5f5f8335601e19843603018112611ece575f5ffd5b8301803591506001600160401b03821115611ee7575f5ffd5b602001915036819003821315611c32575f5ffd5b81818437505f910190815290565b818382375f9101908152919050565b5f5f8335601e19843603018112611f2d575f5ffd5b8301803591506001600160401b03821115611f46575f5ffd5b6020019150600581901b3603821315611c32575f5ffd5b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b5f8383855260208501945060208460051b820101835f5b8681101561200d57838303601f19018852813536879003601e19018112611fc1575f5ffd5b86016020810190356001600160401b03811115611fdc575f5ffd5b803603821315611fea575f5ffd5b611ff5858284611f5d565b60209a8b019a90955093909301925050600101611f9c565b50909695505050505050565b60a081525f61202c60a083018a8c611f5d565b828103602084015261203f81898b611f85565b90506001600160401b03871660408401528281036060840152612063818688611f85565b91505060018060a01b03831660808301529998505050505050505050565b5f8235605e19833603018112612095575f5ffd5b9190910192915050565b60e081525f6120b260e083018c8e611f5d565b82810360208401526120c5818b8d611f85565b905088604084015282810360608401526120e081888a611f85565b608084019690965250506001600160a01b039290921660a083015260c090910152979650505050505050565b634e487b7160e01b5f52604160045260245ffd5b5f5b8381101561213a578181015183820152602001612122565b50505f910152565b5f5f5f60608486031215612154575f5ffd5b835160208501519093506001600160401b03811115612171575f5ffd5b8401601f81018613612181575f5ffd5b80516001600160401b0381111561219a5761219a61210c565b604051601f8201601f19908116603f011681016001600160401b03811182821017156121c8576121c861210c565b6040528181528282016020018810156121df575f5ffd5b6121f0826020830160208601612120565b60409690960151949795965093949350505050565b634e487b7160e01b5f52601160045260245ffd5b8082018082111561222c5761222c612205565b92915050565b6001600160401b03818116838216019081111561222c5761222c612205565b602081525f825180602084015261226f816040850160208701612120565b601f01601f19169190910160400192915050565b8781526001600160a01b03871660208201526001600160401b03861660408201526122b16060820186611ba1565b6122bf610100820185611ba1565b6101c06101a08201525f611ce66101c083018486611c39565b8781526001600160a01b0387166020820152604081018690526122fe6060820186611ba1565b6101406101008201525f61231761014083018587611c39565b82810361012084015261232a8185611da6565b9a9950505050505050505050565b8181038181111561222c5761222c612205565b5f5f85851115612359575f5ffd5b83861115612365575f5ffd5b5050820193919092039150565b80356001600160e01b03198116906004841015611903576001600160e01b031960049490940360031b84901b1690921692915050565b5f81516123b9818560208601612120565b9290920192915050565b8b81526bffffffffffffffffffffffff1960608c811b821660208401528b901b1660348201526001600160e01b031960e08a901b1660488201526001600160f81b031960f889811b8216604c84015288811b8216604d84015287901b16604e8201525f61244661243f612439604f8501896123a8565b876123a8565b8486611efb565b9d9c50505050505050505050505050565b808202811582820484141761222c5761222c612205565b5f6001820161247f5761247f612205565b5060010190565b634e487b7160e01b5f52603260045260245ffd