合约
0x389481ec0e06b540df6ff7856f4c1e68b2db8cce
- 地址
- 0x389481ec0e06b540df6ff7856f4c1e68b2db8cce
- 类型
- 已验证合约 FinalBundleLog
- 余额
- 0 vETH
- Nonce
- 1
- 代码
- 11,619 字节 codehash 0x3a6c46631e4b23970130f9d098e7df5fbf51dfa496681abe92d0ad5fdcaa1cad
账户树
- 树
- 1 · 账户
- 存在
- 无叶
- 键
- 0x872cdece1607ee882a717ebc215b6e0329e180cf71641caec04f0b44353dfc1e
- 实时根
- 0xeae723253d5f6a608807aa960f2b55066f9694cd06953d238148b49b400dce61
此地址在账户树中没有叶。每个 Final Wallet — 包括服务身份 — 都有一个,因此没有叶意味着这是普通账户,而非钱包。
源码 已验证
- 合约
- FinalBundleLog 完全匹配 · immutables 已掩码
- 编译器
- v0.8.33+commit.64118f21
- 优化器
- 已启用 · 200 次运行
- EVM 版本
- prague
- 验证时间
- 2026-09-10T07:09:58.770Z
- 来源
- preverify-final-chain (forge artifact, bytecode compared against live code)
contracts/finalchain/FinalBundleLog.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may deploy and operate this bundle log as part of a
// Final DeFi Protocol chain, and may append to it under the quorum the
// chain recognises.
// 2. Integrators, relayers, and node operators may read its historical roots,
// request inclusion proofs at any past size, and independently re-verify
// any anchor it produced, as part of their integration with the Final DeFi
// Protocol.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this bundle log or a competing post-quantum
// anchoring plane derived from it without permission prior to the Change
// Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
import {FinalMmr} from "../utils/FinalMmr.sol";
import {FinalChainPrecompiles} from "./FinalChainPrecompiles.sol";
import {FinalIntentLog} from "./FinalIntentLog.sol";
import {FinalBundleTree} from "../utils/FinalBundleTree.sol";
import {FinalIdentityRegistry} from "./FinalIdentityRegistry.sol";
import {FinalPqQuorum} from "./FinalPqQuorum.sol";
import {FinalPlaneSweep} from "./FinalPlaneSweep.sol";
/**
* @title FinalBundleLog
* @notice The PQ bundle append-only log, on Final Chain.
*
* Deployed on **Final Chain**, one of the logs the state plane publishes, and
* the one the PQ anchor depends on.
*
* ## Why this exists at all
*
* `PqAnchorModule` has always said where this log lives: the head
* (`masterRoot` @ `mmrSize`) is "advanced by the Final-chain validator set as
* it folds newly-finalized bundles into the MMR". The log itself was never on
* a chain. It lived in a Redis list maintained by a single `mmr-index` worker,
* because Final Chain did not exist and the backend was standing in for it.
*
* That stand-in is what this replaces. The MMR anchor is the **sole
* authorization for PQ execution** — a bundle executes because its root is
* proven under `masterRoot`, and nothing else vouches for it — so the question
* "what is leaf 41?" is a question about custody, and it was being answered by
* a list in a cache that one worker held a lock on.
*
* ## The log answers; nothing folds an MMR to ask it
*
* The obvious cheaper design is to emit leaves and let each reader fold them
* into an MMR itself. It is wrong for this log. Every co-signer would derive
* the root it is about to attest to, so a quorum of correct signers would be
* attesting to their own agreement about a computation rather than to a fact
* the chain states — and a subtly divergent folder in one implementation is
* indistinguishable from a dishonest one.
*
* So the chain states `(root, size)` — and it also states the PROOF. `proofAt`
* and `rootAt` answer for any historical size, so a consumer that needs "leaf
* 41 under the root the gateway anchored" makes one `eth_call` and holds no
* MMR of its own. That closes the last place two implementations of this
* construction had to agree: the backend used to replay `BundleAppended`,
* re-fold every leaf in JavaScript and build the audit path there, which is a
* second folder whose divergence from this one presents as a proof that
* verifies nowhere with both sides internally consistent.
*
* A historical proof is derivable because an MMR node is written ONCE, when
* its perfect subtree completes, and is never revised. Truncating the log to
* `atSize` therefore does not change any node the proof reads — it only
* changes which nodes the border bags — so `proofAt(i, atSize)` is exact for
* every `atSize <= size`, which is what `advanceMmrRoot` lagging behind the
* log requires.
*
* ## Storage: every node, not just the peaks
*
* `_node[level][index]` holds each completed perfect subtree, `_payload[i]`
* the pre-image at each position. That is ~2 slots per leaf and it is what
* makes the two views above possible; the peak bag is derived from `size`
* rather than stored, because a bag kept alongside the nodes would be a second
* representation of one fact.
*
* An append is `O(log n)` worst case and amortised `O(1)`: a leaf carries
* while the two highest peaks are equal-sized, which is binary increment on
* `size`, so the carry count is the number of trailing ones. It is the
* cheapest thing in the PQ path by a wide margin, and on Final Chain — one
* block every 100 ms at a 1 wei base fee — the extra `SSTORE`s cost nothing
* that matters.
*
* ## The layout is exactly `FinalMmr`'s
*
* The log is an RFC-6962 append-only log: perfect subtrees ("peaks") in
* strictly decreasing size, folded right-to-left into the root.
*
* Leaf hashing and the proof's shape come from `FinalMmr` rather than being
* restated — including `bitLength`/`popcount`, which are `internal` there
* precisely so the proof this contract BUILDS and the proof
* `PqAnchorModule.verifyInclusion` CHECKS decompose with one implementation.
* A proof built to one shape and verified against another reverts on the
* gateway naming neither side.
*
* ## Append-only is enforced, not documented
*
* There is no setter for a leaf, no way to shorten the log, and no owner path
* that rewrites one. The only mutation is `append`. A log whose operator can
* revise leaf 41 does not constrain a PQ dispatch at all — it only records
* what the operator was willing to admit, which is what an authorization root
* must not be.
*
* ## Who may append: a PQ quorum, not a role
*
* `FinalPqQuorum` over `ROLE_MMR_COSIGNER`, which is the same roster that
* anchors the head on the execution chains — deliberately, since splitting them
* would create an authority that can admit bundles nobody anchors, or anchor a
* head over leaves nobody admitted.
*
* It was a single `FINAL_MANAGER` role, and that was the largest hole left in
* the PQ lane. Admission IS the authorization: a bundle executes because its
* intent root proves under `masterRoot`, and nothing downstream re-checks it.
* So one compromised manager key admitted an arbitrary bundle and the chain
* then *stated* that root as fact, with every co-signer and every gateway
* correctly deferring to it. A K-of-N quorum of post-quantum signatures, each
* verified by this chain's own precompiles against keys read from the registry
* rather than from calldata, is what makes the log's contents cost more than
* one key.
*
* The whole authority plane moved with it. The log used to answer to a
* `FinalAccessManager`, which does not exist on Final Chain — the registry is
* the only role plane here, so `configure` is gated by it exactly as
* `FinalStateTrees.configureTree` is, and the access-manager pointer and its
* rotation setter are gone rather than left dangling.
*/
contract FinalBundleLog is FinalPlaneSweep {
/// @notice Commitment space. Must equal `PqAnchorModule.DOMAIN_PQ_MMR`, so
/// a proof against this log's root is accepted by the gateway and a proof
/// from any other log is not.
///
/// Restated rather than imported because the gateway declares it
/// `internal` and lives on a different chain — there is no import that
/// would make this one value. `test_DomainMatchesTheGateway` pins the two
/// together; without it, a `_v3` bump on one side would produce a log whose
/// every proof is rejected, and the first symptom would be a PQ bundle that
/// will not dispatch.
bytes32 public constant DOMAIN = keccak256("FINAL_PQ_MMR_NODE_v01");
/// @dev What a co-signer's approval authorizes. Per-action, so an approval
/// to append cannot be replayed as one for any other quorum on this chain.
/// @dev `.v2`: an append is approved over each bundle's INTENT LEAVES now,
/// not over a claimed root. The shapes differ under `abi.encode`, so a v1
/// approval could not be replayed in any case — but the action is what a
/// signer reads to know what it is approving, and it is now approving a
/// different thing.
/// @dev `.v02`: each bundle is approved over its bundle-TERMS leaf as well
/// as its intent leaves. The terms leaf is folded at position 0
/// ahead of the intents, so the anchored root commits to the payout terms
/// the co-signers admitted — dispatch method, recipient, fee cap, flags,
/// includer tip/cap, committed submitter, searcher bids — and a submitter
/// who alters any of them on the execution chain fails `BundleNotAnchored`.
bytes32 private constant ACTION_APPEND = keccak256("FinalBundleLog.append.v02");
/// @dev Standalone leaves: staged-envelope and
/// settlement-credit leaves are MMR entries of their own, appended under
/// the same quorum but consuming nothing from `FinalIntentLog` — they are
/// not intents. A distinct action so an approval to append bundles can
/// never be replayed as one to append payloads, and vice versa.
bytes32 private constant ACTION_APPEND_PAYLOADS = keccak256("FinalBundleLog.appendPayloads.v01");
/// @dev Registrar-quorum action, verified by the registry with this log as
/// the verifying contract.
bytes32 public constant ACTION_CONFIGURE = keccak256("FINAL_BUNDLE_LOG_CONFIGURE_v01");
/// @notice Action tag for the one-shot seeding call.
/// @dev Distinct from the append tag, so an approval collected to seed a fresh log can never be replayed as
/// an ordinary append.
bytes32 public constant ACTION_SEED = keccak256("FINAL_BUNDLE_LOG_SEED_v01");
/// @dev Registrar-quorum action: a fresh log taking over the previous log's
/// LEAVES, payload by payload (the small-log form of {seed}).
bytes32 public constant ACTION_SEED_PAYLOADS = keccak256("FINAL_BUNDLE_LOG_SEED_PAYLOADS_v01");
/// @notice Where every signer, key and role is resolved. Immutable, so the
/// quorum can never be pointed at a registry that arrived in calldata.
FinalIdentityRegistry public immutable registry;
/// @notice The posting log every anchored intent must already appear in.
///
/// @dev Immutable for the same reason as `registry`, and for a sharper one:
/// this is the whole of Final-Chain-first admission. A log that could be
/// repointed could be repointed at one that says yes to everything, and the
/// gate would be gone with nothing on chain looking different.
FinalIntentLog public immutable intentLog;
/// @notice The role a member must hold to approve an append.
uint256 public writerRole;
/// @notice How many approvals one append needs. Zero means unconfigured,
/// and an unconfigured log refuses every write.
uint256 public threshold;
/// @notice Bound into every quorum digest. One per successful `append`
/// call, not per leaf — a batch is one authorization.
uint64 public nonce;
/// @dev Every completed perfect subtree, by level and by index at that
/// level. Written once and never revised — that immutability is the whole
/// reason `proofAt` can answer for a historical `size`.
mapping(uint256 level => mapping(uint256 index => bytes32)) private _node;
/// @dev The pre-image at each position: the bundle's intent-Merkle root,
/// untagged. Stored rather than left to the event log so a consumer needs
/// one `eth_call` and no `getLogs` range — the chain caps that range at
/// 100,000 blocks and mints one every 100 ms.
mapping(uint256 index => bytes32) private _payload;
/// @dev First position a payload took, plus one. Zero means never
/// appended. First-occurrence-wins: a duplicate bundle root is a duplicate
/// bundle, and either position proves the same root under the same head,
/// so the earlier one is the one a lagging anchor can already reach.
mapping(bytes32 payload => uint256) private _firstIndexPlusOne;
/// @notice Leaf count. The `size` half of the head the execution chains'
/// `advanceMmrRoot` is called with.
uint256 public size;
/// @notice Current log root over all `size` leaves — the `root` half of
/// that head. Zero exactly when `size == 0`: an empty log commits to no
/// leaves, matching `FinalMmr.MmrEmptyLog`.
bytes32 public root;
/// @notice A bundle root was folded in at `index`.
/// @dev Carries the payload AND the resulting head, so a reader that wants
/// the log replays this event and needs no other source. `payload` is the
/// pre-image (the bundle's intent-Merkle root), not the tagged leaf — a
/// consumer proving inclusion re-tags it via `FinalMmr.hashLeaf`, and
/// emitting the tagged form would invite proving against the wrong one.
event BundleAppended(uint256 indexed index, bytes32 indexed payload, bytes32 root, uint256 size);
/// @notice The writer role or the threshold moved.
event LogConfigured(uint256 writerRole, uint256 threshold);
/// @notice A fresh log took over the previous log's frontier.
event Seeded(uint256 size, uint256 peaks);
/// @notice A fresh log took over the previous log's leaves, whole.
event SeededPayloads(uint256 size);
/// @notice `payload` is zero. A zero leaf is almost always an uninitialised
/// read upstream, and it is unrecoverable here: the log cannot be shortened.
error ZeroBundleRoot();
/// @notice The frontier can be seeded only into an empty log.
error NotFresh();
/// @notice Thrown when a supplied peak set does not match the peaks the log currently holds.
/// @dev The peaks are what a new root folds from, so accepting a mismatched set would publish a root that
/// describes a history this log never had.
/// @param expected The number of peaks the log holds.
/// @param given The number supplied.
error PeaksMismatch(uint256 expected, uint256 given);
/// @notice A view was asked about more leaves than the log holds.
error SizeAhead(uint256 asked, uint256 held);
/// @notice The audit-path walk and the `(index, size)` decomposition
/// disagreed about how many siblings a proof has.
error ProofShapeMismatch(uint256 expected, uint256 walked);
/// @notice `append` with no leaves. A quorum round that admits nothing is
/// always a caller bug, and burning a nonce for it would invalidate every
/// approval already collected for the real batch.
error EmptyBatch();
/// @notice `threshold` is zero: no quorum has been configured yet.
error LogNotConfigured();
/// @notice A threshold no live roster can meet. Register the members first.
error ThresholdUnreachable(uint256 live, uint256 required);
/// @notice Not the bootstrap admin and not a registrar.
error NotAuthorized(address caller);
/// @dev A bundle with no intents has no root to fold and nothing to consume.
error EmptyBundleLeaves(uint256 bundleIndex);
/// @notice Thrown when the zero address is offered as the intent log.
error ZeroIntentLog();
/// @notice `append` was handed a different number of terms leaves than
/// bundles — every bundle carries exactly one.
error TermsLeafCountMismatch(uint256 termsLeaves, uint256 bundles);
/// @notice A bundle's terms leaf was zero. The terms are what the
/// co-signers admitted; a bundle with none has no admitted payout terms.
error ZeroTermsLeaf(uint256 bundleIndex);
/**
* @param registry_ The identity registry. Every signer, key and role comes
* from it, and it is fixed at deployment for the same reason the
* keys are read from storage: a registry supplied per call is a
* registry the caller chooses.
*
* @dev A constructor, unlike the salt-only contracts in `contracts/`. This
* one is deployed by ordinary CREATE alongside `FinalIdentityRegistry` and
* `FinalStateTrees` — it lives on exactly one chain, so an address that is
* identical across chains buys nothing, and the vanity path costs a
* `FinalDeployer` bootstrap Final Chain has no other use for.
*
* The precompile probe is the point of having one at all: a log deployed
* where ML-DSA cannot be verified would accept no approval it was ever
* given, and the first symptom would be a PQ lane that silently never
* admits a bundle.
*/
constructor(FinalIdentityRegistry registry_, FinalIntentLog intentLog_) {
FinalChainPrecompiles.assertAvailable();
if (address(intentLog_) == address(0)) revert ZeroIntentLog();
registry = registry_;
intentLog = intentLog_;
}
/**
* @notice Set which role may approve an append, and how many approvals.
* @dev The registry's bootstrap admin alone while its window is open, the
* sealed `ROLE_REGISTRAR` quorum afterwards — the same window and the same
* quorum the registry and the trees use, because a threshold is membership
* by another name. `approvals` is empty during bootstrap.
*
* Deliberately re-callable. A co-signer set that grows or shrinks has to be
* able to move its threshold, and the alternative is a log that must be
* redeployed — which for an append-only log means abandoning its contents.
*/
function configure(
uint256 role,
uint256 k,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
if (registry.bootstrapSealed() || msg.sender != registry.bootstrapAdmin()) {
registry.requireRegistrarQuorum(
ACTION_CONFIGURE, keccak256(abi.encode(role, k)), anchorBlock, approvals
);
}
// Refuse a threshold nobody can meet. A 4-of-5 configured against three
// registered co-signers is a log that reverts on every append, and the
// revert would name the threshold rather than the roster.
if (k != 0) {
uint256 live = registry.liveMemberCount(role);
if (live < k) revert ThresholdUnreachable(live, k);
}
writerRole = role;
threshold = k;
emit LogConfigured(role, k);
}
/**
* @notice Take over the previous log's frontier — its `peaks()` and `size`
* — so appends continue at the old positions and the accumulator
* (roots, `masterRoot @ mmrSize` on every gateway) never runs
* backwards across a redeploy. A redeploy does NOT wipe.
* @dev The peaks are stored as the nodes they are (level = bit, index =
* leaves-before >> level), which is all a future append or `peaksAt`
* ever reads. Leaves BELOW the seed are the old log's: `payloadAt`
* and proofs for them answer from there, not here. Same authority as
* {configure}; only while this log holds nothing.
*/
function seed(
bytes32[] calldata peaks_,
uint256 size_,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
if (registry.bootstrapSealed() || msg.sender != registry.bootstrapAdmin()) {
registry.requireRegistrarQuorum(
ACTION_SEED, keccak256(abi.encode(peaks_, size_)), anchorBlock, approvals
);
}
if (size != 0) revert NotFresh();
uint256 expected;
for (uint256 x = size_; x != 0; x >>= 1) {
if (x & 1 == 1) expected++;
}
if (expected != peaks_.length) revert PeaksMismatch(expected, peaks_.length);
uint256 prefix;
uint256 p;
for (uint256 level = 255; ; level--) {
if ((size_ >> level) & 1 == 1) {
if (peaks_[p] == bytes32(0)) revert ZeroBundleRoot();
_node[level][prefix >> level] = peaks_[p++];
prefix += (uint256(1) << level);
}
if (level == 0) break;
}
size = size_;
// `head()` answers (root, size) as one pair; a seeded size beside a
// zero root is a torn head until the first append recomputes it.
root = size_ == 0 ? bytes32(0) : rootAt(size_);
emit Seeded(size_, peaks_.length);
}
/**
* @notice Take over the previous log's LEAVES — every payload, in order —
* so this log answers `payloadAt`, `indexOf`, `proofAt` and
* `peaksAt` for every position the old one did, with the same
* roots at every size. The small-log form of {seed}: a peak-seeded
* log holds no payload below its seed, and the first live one
* was seeded one leaf ABOVE what the gateways had
* anchored — the proposer could not read that leaf's payload here,
* could not build a verifiable proposal, and every anchor stalled
* behind it. Copying the leaves has no such edge; it costs one
* fold per leaf, which on this chain is cheap for a log of
* thousands. Same authority as {configure}; only while this log
* holds nothing.
*/
function seedPayloads(
bytes32[] calldata payloads,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
if (registry.bootstrapSealed() || msg.sender != registry.bootstrapAdmin()) {
registry.requireRegistrarQuorum(
ACTION_SEED_PAYLOADS, keccak256(abi.encode(payloads)), anchorBlock, approvals
);
}
if (size != 0) revert NotFresh();
if (payloads.length == 0) revert EmptyBatch();
for (uint256 i = 0; i < payloads.length; i++) {
_append(payloads[i]);
}
emit SeededPayloads(payloads.length);
}
/**
* @notice Fold one or more bundles in as the next leaves, under a
* post-quantum quorum.
* @param termsLeaves One bundle-terms leaf per bundle —
* `keccak256(abi.encode(DOMAIN_BUNDLE_TERMS, chainId, method,
* recipient, maxFeeWei, bundleFlags, tipPerGas, capPerGas,
* submitter, bidsHash, systemCallsHash))`, exactly as the execution
* chain's gateway rebuilds it. Folded at position 0, ahead of the
* intents; never consumed from the intent log, because it is not an
* intent.
*
* `systemCallsHash` is the eleventh word: the left fold
* `hᵢ₊₁ = keccak256(hᵢ ‖ targetᵢ ‖ bindingᵢ)` over the bundle's
* carried system calls, zero when it carries none. It binds the
* count and the destinations of the calls the co-signers admitted,
* so a submitter cannot append one and be compensated for its gas.
* `bindingᵢ` is `keccak256(dataᵢ)` for a call the execution chain's
* gateway makes to ITSELF under a selector that is not
* self-anchoring, and zero otherwise: every other target's payload
* carries its own K-of-N or inclusion proof, while the gateway's
* refill self-calls are authorized by the caller alone and were
* rewritable by whoever submitted the bundle. The exclusion covers
* `advanceMmrRoot(bytes32,uint256)` only — binding that would close
* a loop on the bundle carrying the advance that anchors it.
* @param bundles One inner array per bundle: that bundle's intent leaves,
* in bundle order. The root is RECOMPUTED from `[terms, leaves…]`.
* @param approvals At least `threshold` of them, ascending by signer.
* @return firstIndex The 0-based position the FIRST leaf occupies, forever.
*
* @dev **Leaves, not a root.** A claimed root is a claim about intents
* nobody on this chain checked. Taking the leaves lets the contract do two
* things it could not do before: recompute the payload with the same fold
* the execution chain's gateway uses, and require every leaf to be an open
* posting in `FinalIntentLog`.
*
* That is what makes Final-Chain-first admission a mechanism instead of a
* quorum policy. A bundle cannot be anchored unless every intent in it was
* posted here first, and since the execution chains' whole authorization is
* this log's head, an intent that was never posted can never execute. The
* co-signers already recomputed the root off-chain in
* `validateBundleForAnchor`; this moves the check to where a compromised
* quorum cannot skip it.
*
* Consumption is also the anti-replay gate for intents. The execution chain
* keeps a consumed-seqId set that stops a BUNDLE re-executing; it cannot see
* one intent being re-anchored inside a second bundle. This can.
*
* A batch rather than a leaf, because the quorum round — not the
* `O(log n)` carry — is what an append costs. One round per bundle would
* put a K-of-N collection on the critical path of every PQ dispatch; one
* round per run of bundles is the same authorization over more work. A
* batch of one is the degenerate case and is exactly as safe.
*
* The digest binds the nonce AND the pre-append `size`, so a co-signer
* approves the POSITIONS as well as the contents. `size` is redundant for
* replay — the nonce already covers that — and it is not redundant for what
* this log is: "what is leaf 41?" is the question the whole contract exists
* to answer, and an approval that named the leaves but not where they
* land would leave that answer to whoever assembled the transaction.
*
* ML-DSA-87 is required rather than accepted, AND every approval carries a
* seal. Admission is the authorization for execution — a root that lands
* here executes — so it takes both key classes: the transaction key's
* ML-DSA-87 signature and the seal key's SLH-DSA-SHAKE-256s over the same
* digest. A break in either family leaves the log unmovable rather than
* taken. `anchorBlock` is the tree-1 view the members decided the roster
* against; `FinalPqQuorum.require_` bounds how stale it may be.
*/
function append(
bytes32[] calldata termsLeaves,
bytes32[][] calldata bundles,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external returns (uint256 firstIndex) {
if (bundles.length == 0) revert EmptyBatch();
if (termsLeaves.length != bundles.length) revert TermsLeafCountMismatch(termsLeaves.length, bundles.length);
uint256 k = threshold;
if (k == 0) revert LogNotConfigured();
uint64 n = nonce;
firstIndex = size;
FinalPqQuorum.require_(
registry,
approvals,
FinalPqQuorum.digest(
address(this),
ACTION_APPEND,
anchorBlock,
keccak256(abi.encode(n, firstIndex, termsLeaves, bundles))
),
writerRole,
k,
FinalPqQuorum.ALG_ML_DSA_87,
anchorBlock,
true
);
nonce = n + 1;
for (uint256 i = 0; i < bundles.length; i++) {
bytes32[] calldata leaves = bundles[i];
if (leaves.length == 0) revert EmptyBundleLeaves(i);
if (termsLeaves[i] == bytes32(0)) revert ZeroTermsLeaf(i);
// Consume BEFORE folding. Either order works today, but consuming
// first means a bundle that names an unposted or already-spent leaf
// reverts on the leaf itself rather than after doing the fold — and
// the revert names which leaf, which is the thing an operator needs.
// The terms leaf sits at position 0 and is NOT consumed: it is the
// admitted payout terms, not a posting.
bytes32[] memory layer = new bytes32[](leaves.length + 1);
layer[0] = termsLeaves[i];
for (uint256 j = 0; j < leaves.length; j++) {
intentLog.consume(leaves[j]);
layer[j + 1] = leaves[j];
}
_append(FinalBundleTree.foldLeaves(layer));
}
}
/**
* @notice Append standalone leaves — staged-envelope and settlement-credit
* commitments — under the same post-quantum
* quorum, consuming nothing.
* @param payloads The leaf preimages, already domain-separated by their
* own kind (`DOMAIN_STAGED_ENVELOPE`, `DOMAIN_SETTLEMENT_CREDIT` on
* the gateway side). Each becomes one position in the log and is
* provable to any gateway exactly as a bundle root is.
* @return firstIndex The 0-based position the FIRST payload occupies.
*
* @dev These are not intents and were never posted, so nothing is consumed
* from `FinalIntentLog`; what authorizes them is what authorizes a bundle
* root — K of N co-signers, each of whom recomputed the leaf from the facts
* it commits to (a settlement credit from the collecting chain's recorded
* charge and the terminal execution fact; a staged envelope from the
* admitted intent's anchored bound) before signing. A separate action id
* keeps a bundle approval from being replayed here and vice versa; the
* digest binds the nonce and the pre-append size, so positions are approved
* along with contents, as for `append`.
*/
function appendPayloads(
bytes32[] calldata payloads,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external returns (uint256 firstIndex) {
if (payloads.length == 0) revert EmptyBatch();
uint256 k = threshold;
if (k == 0) revert LogNotConfigured();
uint64 n = nonce;
firstIndex = size;
FinalPqQuorum.require_(
registry,
approvals,
FinalPqQuorum.digest(
address(this),
ACTION_APPEND_PAYLOADS,
anchorBlock,
keccak256(abi.encode(n, firstIndex, payloads))
),
writerRole,
k,
FinalPqQuorum.ALG_ML_DSA_87,
anchorBlock,
true
);
nonce = n + 1;
for (uint256 i = 0; i < payloads.length; i++) {
_append(payloads[i]);
}
}
/// @dev The fold itself. Separated from authorization so the batch loop is
/// one concern and the quorum is the other.
function _append(bytes32 payload) private {
if (payload == bytes32(0)) revert ZeroBundleRoot();
uint256 index = size;
_payload[index] = payload;
// First occurrence wins, so `indexOf` is stable for the life of the
// log. A later duplicate is still appended and still provable at its
// own position; it just is not the one this lookup names.
if (_firstIndexPlusOne[payload] == 0) _firstIndexPlusOne[payload] = index + 1;
// Push the new leaf as a size-1 peak, then carry while the top two
// peaks are equal-sized. Equal size is exactly "the low bits of the
// pre-increment count are set", so the carry count is the number of
// trailing ones — binary increment, and the reason this is amortised
// O(1) rather than O(log n) per append.
bytes32 carry = FinalMmr.hashLeaf(DOMAIN, payload);
_node[0][index] = carry;
uint256 completed = index; // leaves already in the log
uint256 level = 0;
while (completed & 1 == 1) {
// The left sibling is the perfect subtree that ends where this one
// begins, and it is already stored — `_append` is the only writer
// and it wrote that node on the append that completed it.
//
// Positional: the earlier subtree is always the LEFT child. Sorting
// the pair here would make two different logs hash alike and is the
// second-preimage hole `FinalMmr`'s tags exist to close.
bytes32 left = _node[level][completed - 1];
carry = _hashNode(left, carry);
unchecked {
completed >>= 1;
++level;
}
_node[level][completed] = carry;
}
unchecked {
size = index + 1;
}
root = rootAt(size);
emit BundleAppended(index, payload, root, size);
}
// ------------------------------------------------------------------ reads
/// @notice The pre-image at one position — the bundle's intent-Merkle root.
/// @dev Untagged, as the event carries it. A consumer proving inclusion
/// re-tags through `FinalMmr.hashLeaf`; returning the tagged form here
/// would invite proving against the wrong one.
function payloadAt(uint256 index) public view returns (bytes32) {
if (index >= size) revert FinalMmr.MmrIndexOutOfRange(index, size);
return _payload[index];
}
/// @notice The pre-images at `[from, to)`, in order.
/// @dev Batched because the proposer needs every unanchored leaf between
/// the gateway's head and this log's, and one `eth_call` per leaf turns a
/// pass into `size` round trips on a chain that mints a block every 100 ms.
function payloadsBetween(uint256 from, uint256 to) external view returns (bytes32[] memory out) {
if (to > size) revert SizeAhead(to, size);
if (from > to) revert FinalMmr.MmrIndexOutOfRange(from, to);
out = new bytes32[](to - from);
for (uint256 i = from; i < to; ) {
out[i - from] = _payload[i];
unchecked { ++i; }
}
}
/// @notice Where a bundle root first landed.
/// @return index Its position. @return found False when it never landed,
/// which is a state — a proposed bundle that has not been admitted yet —
/// rather than an error.
function indexOf(bytes32 payload) external view returns (uint256 index, bool found) {
uint256 plusOne = _firstIndexPlusOne[payload];
if (plusOne == 0) return (0, false);
return (plusOne - 1, true);
}
/// @notice The peak bag backing the current root.
/// @dev Derived from `size` rather than stored: a bag kept alongside the
/// nodes would be a second representation of one fact, and the interesting
/// property — `length == popcount(size)` — is then a consequence rather
/// than something to maintain.
function peaks() external view returns (bytes32[] memory) {
return peaksAt(size);
}
/// @notice The peak bag as of `atSize` leaves.
function peaksAt(uint256 atSize) public view returns (bytes32[] memory bag) {
if (atSize > size) revert SizeAhead(atSize, size);
bag = new bytes32[](FinalMmr.popcount(atSize));
uint256 n = 0;
uint256 offset = 0;
uint256 level = FinalMmr.bitLength(atSize);
// MSB first, so the peaks come out largest-first — the order
// `_rootFromPeaks` and every reader expect.
while (level > 0) {
unchecked { --level; }
if ((atSize >> level) & 1 == 1) {
bag[n] = _node[level][offset >> level];
unchecked {
++n;
offset += (1 << level);
}
}
}
}
/// @notice The head the execution chains' `advanceMmrRoot` should be called
/// with, read in one call so the pair can never be torn across two.
function head() external view returns (bytes32 root_, uint256 size_) {
return (root, size);
}
/**
* @notice The root over the FIRST `atSize` leaves.
* @dev Exact for every `atSize <= size`, not only the current one, because
* an MMR node is written once and never revised. That is what lets a
* consumer prove against the head the gateway actually anchored, which
* lags this log by design — a proof built against a larger size is
* well-formed and verifies nowhere.
*/
function rootAt(uint256 atSize) public view returns (bytes32) {
if (atSize > size) revert SizeAhead(atSize, size);
if (atSize == 0) return bytes32(0);
return _rangeRoot(0, atSize);
}
/**
* @notice The audit path proving leaf `leafIndex` under `rootAt(atSize)`.
* @param leafIndex 0-based position, `< atSize`.
* @param atSize The head to prove against — `gateway.mmrSize()`, not this
* log's size, whenever the two differ.
*
* @dev The walk is the Trillian formulation: rise level by level and record
* the sibling, which is a stored perfect subtree unless it is the ragged
* last node of its level, in which case it is the bag of the peaks that
* remain. Both cases resolve to nodes this contract wrote, so there is
* nothing to recompute from leaves and nothing for a caller to fold.
*
* The result feeds `FinalMmr.computeRoot` verbatim on the gateway. Its
* length is derived here from the same `(index, size)` decomposition that
* verifier uses, and the walk's own count is checked against it — a
* disagreement is a proof rejected on another chain naming neither side,
* so it is caught where both derivations are visible.
*/
function proofAt(uint256 leafIndex, uint256 atSize) public view returns (bytes32[] memory proof) {
if (atSize > size) revert SizeAhead(atSize, size);
if (atSize == 0) revert FinalMmr.MmrEmptyLog();
if (leafIndex >= atSize) revert FinalMmr.MmrIndexOutOfRange(leafIndex, atSize);
uint256 inner = FinalMmr.bitLength(leafIndex ^ (atSize - 1));
uint256 border = FinalMmr.popcount(leafIndex >> inner);
proof = new bytes32[](inner + border);
uint256 idx = leafIndex;
uint256 last = atSize - 1; // index of the last node at the current level
uint256 level = 0;
uint256 n = 0;
while (last != 0) {
uint256 sibling = idx ^ 1;
if (sibling < last) {
// A complete perfect subtree, stored when it completed.
proof[n] = _node[level][sibling];
unchecked { ++n; }
} else if (sibling == last) {
// The ragged right edge: this level's last node may cover fewer
// than `2 ** level` leaves, so it is the bag of the peaks in
// `[sibling << level, atSize)` rather than a node of its own.
proof[n] = _rangeRoot(sibling << level, atSize);
unchecked { ++n; }
}
// `sibling > last` — no sibling at this level. Rise without
// recording, which is what makes an imperfect tree's path shorter
// than its depth.
unchecked {
idx >>= 1;
last >>= 1;
++level;
}
}
if (n != proof.length) revert ProofShapeMismatch(proof.length, n);
}
/**
* @notice Everything needed to prove one bundle, in one call.
* @dev One call rather than three, because payload, proof and root are only
* meaningful together: fetched separately, an append landing between two of
* them yields a proof against a root the caller did not read, and the
* dispatch reverts on another chain with three individually-correct values.
*/
function bundleAt(uint256 leafIndex, uint256 atSize)
external
view
returns (bytes32 payload, bytes32[] memory proof, bytes32 root_)
{
proof = proofAt(leafIndex, atSize);
payload = payloadAt(leafIndex);
root_ = rootAt(atSize);
}
/**
* @dev The Merkle-Tree-Hash of leaves `[lo, hi)`, where `lo` is aligned to
* the largest perfect subtree the range can hold.
*
* Every part is a COMPLETE perfect subtree and therefore a stored node,
* which is the property that makes a historical proof derivable at all.
* The parts come out largest-first and fold right-to-left, which is the
* same peak bag `FinalMmr.computeRoot` walks as a proof's border — and is
* what makes a proof against this root verify on the gateway.
*/
function _rangeRoot(uint256 lo, uint256 hi) private view returns (bytes32) {
uint256 remaining = hi - lo;
bytes32[] memory bag = new bytes32[](FinalMmr.popcount(remaining));
uint256 n = 0;
uint256 offset = lo;
uint256 level = FinalMmr.bitLength(remaining);
while (level > 0) {
unchecked { --level; }
if ((remaining >> level) & 1 == 1) {
bag[n] = _node[level][offset >> level];
unchecked {
++n;
offset += (1 << level);
}
}
}
bytes32 acc = bag[n - 1];
for (uint256 i = n - 1; i > 0; ) {
unchecked { --i; }
acc = _hashNode(bag[i], acc);
}
return acc;
}
/// @dev `FinalMmr` keeps its node hash private (proof verification is its
/// only caller there), so the one construction that must not fork is
/// restated once, here, against its published spec:
/// `keccak256(0x01 ‖ domain ‖ left ‖ right)`. `test_LayoutMatchesFinalMmr`
/// pins it against a proof the library itself verifies, so a change to
/// either side fails rather than producing a log the gateway rejects.
function _hashNode(bytes32 left, bytes32 right) private pure returns (bytes32) {
return keccak256(abi.encodePacked(uint8(0x01), DOMAIN, left, right));
}
// ------------------------------------------------------------------ sweep
/// @dev This contract's configuration gate reads the membership registry it
/// was constructed against, so the sweep authority reads the same one.
function _sweepRegistry() internal view override returns (FinalIdentityRegistry) {
return registry;
}
/// @dev Nothing is reserved because nothing is owed: this contract has no
/// payable entrypoint and no custody line — it records, it does not hold.
/// Anything it carries arrived by accident and is sweepable in full.
}
contracts/finalchain/FinalCertificate.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may link against and call this certificate reader,
// and may encode certificates that it accepts, as part of the Final DeFi
// Protocol.
// 2. Operators, integrators, and end users may have their certificates parsed,
// self-checked, and verified through any Final DeFi surface that links it.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this certificate reader or a competing identity
// certificate format derived from it without permission prior to the
// Change Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
import {FinalChainPrecompiles} from "./FinalChainPrecompiles.sol";
import {FinalChainTime} from "./FinalChainTime.sol";
/**
* @title Final Certificate
* @notice Reads a Final Certificate on chain and self-checks it, so a certificate's keys can never be
* anything other than the keys it declares.
* @dev Deployed only as part of this project's own reth-based state plane, and only on the reth-based chains
* that carry the precompiles it calls: SHA3-256 at `0x0202`, ML-DSA-87 at `0x0204` and
* SLH-DSA-SHAKE-256s at `0x0205`, each address being that primitive's FIPS number. The contracts it is
* linked into probe those precompiles at construction and refuse to exist where they are absent, so
* this library never runs somewhere its verdicts would be meaningless. It takes part in no CREATE2
* derivation, and nothing outside this directory imports it.
*
* The SHA3 precompile is not a convenience: the certificate format hashes with FIPS-202 SHA3 and the
* EVM's `keccak256` is a DIFFERENT function, so a digest computed with the wrong one matches no
* certificate any issuer ever wrote.
*
* ## Why the chain parses this at all
*
* The alternative is taking the TBS bytes and the public keys as separate arguments and deriving
* `certHash` from the bytes. That looks like verification and is not: nothing compares the keys to the
* certificate, so a registrar could bind any certificate to any keypair, the registry would hold a key
* the certificate does not contain, and every signature that key produced would verify against a
* certificate that never authorised it.
*
* So the keys are read OUT of the certificate. There is one input, and no pair of arguments that can
* disagree.
*
* Gas is deliberately not a design constraint on the chain this runs on and must not be optimised for.
* Parsing and re-hashing on chain costs more than trusting a parse done elsewhere and buys a verdict
* that is re-derivable from public state, which is the trade this whole plane is built on.
*
* ## The key-identifier check
*
* A certificate declares `SubjectKeyId` as the SHA3-256 digest of its `PublicKeyBlock`. Having parsed
* that block, {parse} recomputes the digest and compares. The field sits inside the TBS, so it is
* covered by the issuer's signatures — which makes the check a statement about what the issuer
* attested, not merely about internal consistency of bytes the caller supplied.
*
* ## Deploy-linked, not inlined
*
* {parseLive}, {parseRecovery}, {parseCa} and {verifyIssuerSignatures} are `external`, so the identity
* registry calls them across a link boundary rather than carrying them in its own bytecode, which it
* has no room for. The link target is fixed at deployment: a linked library is code, not a pointer
* anyone can move afterwards.
*
* ## What this library deliberately does not do
*
* It does not verify an issuer's signatures over the TBS as part of parsing, and it does not walk a
* certificate chain to the root. On the registration path there is nothing to walk — a chain-attested
* certificate is admitted by this chain against pinned issuer constants and the holder's own proof of
* possession, so an issuer signature is not what makes it valid. {verifyIssuerSignatures} is here for
* callers verifying an off-chain issuance, and it verifies exactly what it is handed.
*
* It also does not check an encapsulation key's length or structure. Those are checked where they are
* REGISTERED, by the precompiles that own the answer, because two checks of one thing in two shapes is
* how one of them ends up weaker and nobody notices which.
*/
library FinalCertificate {
/// @notice The four magic bytes every certificate opens with, `"PQCF"`.
uint32 internal constant MAGIC = 0x50514346;
/// @notice The current wire generation, which encoders write.
/// @dev A generation this parser does not know fails to parse rather than being reinterpreted: the
/// folded key commitment, and therefore every wallet address, derives from this exact layout, so a
/// layout read under the wrong generation would produce a self-consistent digest that matches
/// nothing.
uint32 internal constant VERSION = 2;
/// @notice The previous wire generation, still accepted on parse.
/// @dev Reading an older artifact is not the same as admitting it. Whether such a certificate may be
/// REGISTERED is settled at admission, by the holder's proof of possession and the chain-issuer
/// pins, rather than by refusing to decode it.
uint32 internal constant VERSION_V4 = 1;
/// @notice The institution identity extension, which carries an issuer's legal name, registration
/// number and jurisdiction.
uint16 internal constant EXT_INSTITUTION = 0x0102;
/// @notice ML-KEM-1024 (FIPS 203), the lattice half of the encapsulation pair.
/// @dev Algorithm identifiers ARE the FIPS numbers, in one space shared by signatures and encapsulation
/// — the same identifiers the quorum wire format uses, and the numbers the precompile addresses end
/// in. One space rather than two means an identifier can never be read against the wrong table.
uint16 internal constant ALG_ML_KEM_1024 = 0x0003;
/// @notice ML-DSA-87 (FIPS 204). Transaction class.
uint16 internal constant ALG_ML_DSA_87 = 0x0004;
/// @notice SLH-DSA-SHAKE-256s (FIPS 205). Access class, and the seal.
uint16 internal constant ALG_SLH_DSA_SHAKE_256S = 0x0005;
/// @notice FN-DSA (FIPS 206). Reserved: there is no implementation behind it and it is never accepted in
/// a slot.
uint16 internal constant ALG_FN_DSA = 0x0006;
/// @notice HQC-5 (FIPS 207), the code-based half of the encapsulation pair.
uint16 internal constant ALG_HQC_5 = 0x0007;
/// @notice Certificate signing, for both of an issuer's keys.
/// @dev Says which key to verify WITH; it grants nothing on its own — capability to issue comes from the
/// depth pair.
uint16 internal constant PURPOSE_CERT_SIGNING = 0x0004;
/// @notice The live stage's transaction-class slot, ML-DSA-87.
/// @dev A wallet holds four slots in two stages of two, and a certificate carries ONE stage, never all
/// four. The stage is what is issued, rotated and revoked as a unit, and a holder presenting a live
/// certificate presents both of that stage's keys or neither — splitting them per slot would let
/// half a stage be presented as if it were whole.
/// @dev This applies to services exactly as it applies to a user's wallet. A co-signer is a Final
/// Wallet: same four slots, same split, same algorithms. There is no second kind of identity in
/// this system.
uint16 internal constant PURPOSE_ACTIVE_TX = 0x0010;
/// @notice The live stage's access-class slot, SLH-DSA-SHAKE-256s.
uint16 internal constant PURPOSE_ACTIVE_ACCESS = 0x0011;
/// @notice The recovery stage's transaction-class slot, ML-DSA-87.
uint16 internal constant PURPOSE_RECOVERY_TX = 0x0012;
/// @notice The recovery stage's access-class slot, SLH-DSA-SHAKE-256s.
uint16 internal constant PURPOSE_RECOVERY_ACCESS = 0x0013;
/// @notice The live stage's encapsulation slot.
/// @dev Each stage's encapsulation pair is resolved alongside its signing pair, and the identity
/// registry stores both halves, so a sender can encapsulate to a registered party without a second
/// lookup somewhere less authoritative. Both halves sit under ONE purpose and are told apart by
/// algorithm, which is why the key loop matches on the `(purpose, algorithm)` pair.
uint16 internal constant PURPOSE_ACTIVE_KEM = 0x0014;
/// @notice The recovery stage's encapsulation slot, carrying the same two algorithms.
uint16 internal constant PURPOSE_RECOVERY_KEM = 0x0015;
/// @notice The seal purpose: a second SLH-DSA-SHAKE-256s key that co-signs execution-class quorum
/// decisions.
/// @dev Distinct from the access key, and carried by SERVICE certificates only — a user's wallet never
/// seals. Optional in the format, so a certificate without it parses unchanged.
/// @dev Outside the folded key commitment: a seal is operational, rotated by issuing a new live
/// certificate, and it must not move a wallet address it plays no part in deriving.
uint16 internal constant PURPOSE_ACTIVE_SEAL = 0x0016;
/// @notice A sentinel purpose no certificate can carry.
/// @dev Lets {parse} be told "this stage has no encapsulation slot" without a second boolean argument.
/// `0xffff` is outside the purpose registry and is reserved by being used here.
uint16 internal constant NO_KEM_PURPOSE = 0xffff;
/// @notice Nanoseconds per millisecond, the conversion from a certificate's validity fields to this
/// chain's clock.
/// @dev A certificate stamps validity in NANOseconds and this chain's clock is MILLIseconds, so the
/// parser divides by 1e6 on the way in and nothing downstream ever compares across units. Getting
/// the divisor wrong does not fail loudly: it shifts every window by three orders of magnitude, so
/// every certificate reads as already valid, including one issued for the future.
uint64 internal constant NS_PER_MILLISECOND = FinalChainTime.NS_PER_MILLISECOND;
/**
* @title Parsed
* @notice What the chain keeps out of one certificate.
* @dev Every field is read OUT of the TBS. Nothing here can be supplied alongside the bytes, which is
* what makes it impossible for a caller to bind a certificate to material the certificate does not
* contain.
*/
struct Parsed {
/// `SHA3-256` of the TBS bytes: the certificate's own identity, and the handle revocation is keyed
/// on.
bytes32 certHash;
/// The certificate's 32-byte serial. A serial is per certificate SET, so the two stages of one
/// wallet share it and two stages that disagree are two different wallets.
bytes32 serial;
/// keccak256 of the issuer-name bytes, for the chain-issuer pin: a chain-attested certificate
/// carries the chain's own constant issuer name, and the registry compares one hash rather than two
/// strings.
bytes32 issuerDnHash;
/// The subject-name bytes verbatim. Kept whole rather than hashed because the jurisdiction rule
/// reads its country component at issuer registration.
bytes subjectDn;
/// The institution extension's VALUE, when present; empty otherwise. Issuer registration parses
/// the declared jurisdiction out of it and requires it to match the subject name's country.
bytes institutionExt;
/// SHA3-256 of the ISSUER's public key block. Zero-length — and so
/// `bytes32(0)` here — for exactly one certificate in the hierarchy,
/// which is what terminates chain validation.
bytes32 authorityKeyId;
/// SHA3-256 of this certificate's own public key block. The child's
/// `authorityKeyId` must equal it, which is what links the two.
bytes32 subjectKeyId;
/// Position on the delegation axis; 0 is the chain's own root.
uint8 depth;
/// Deepest level this key may issue to. `== depth` means it signs no certificates at all, which is
/// every end entity. The pair is immutable per certificate, which is why consumers discriminate
/// record kinds by it rather than by a role bit.
uint8 maxDelegationDepth;
/// MILLISECONDS, converted from the schema's nanoseconds — this chain's clock.
uint64 notBefore;
/// Milliseconds. Zero means never expires, which the schema allows.
uint64 notAfter;
/// The stage's transaction-class key. ML-DSA-87 — spending, and every
/// high-cadence protocol action.
bytes transactionKey;
/// The stage's access-class key. SLH-DSA-SHAKE-256s — identity,
/// rotation, recovery-pair promotion. A different hardness assumption,
/// so a lattice break leaves the key that governs identity standing.
bytes accessKey;
/// The stage's ML-KEM-1024 encapsulation key. Empty on a CA, which has
/// no encapsulation stage, and on any v4 certificate issued without
/// one — see `parse` for why that is tolerated rather than refused.
bytes kemMlKem;
/// The stage's HQC-5 encapsulation key. Carried under the SAME purpose
/// as the lattice half and distinguished only by algorithm, which is
/// why the parser matches on the `(purpose, algorithm)` pair.
bytes kemHqc;
/// The service's seal key (`PURPOSE_ACTIVE_SEAL`, SLH-DSA-SHAKE-256s).
/// Empty on every certificate that does not carry one — a user wallet,
/// a recovery stage, a CA.
bytes sealKey;
/// Where the TBS ends, so a caller holding the whole certificate can
/// find the `SignatureBlock` without parsing forward again.
uint256 tbsLength;
}
/// @notice The bytes do not open with the certificate magic, so they are not a certificate at all.
/// @param got The four bytes that were present.
error BadMagic(uint32 got);
/// @notice The wire generation is one this parser does not read.
/// @param got The generation the certificate declares.
error BadVersion(uint32 got);
/// @notice The TBS ends before a field the parser was about to read.
/// @param needed The offset the read required.
/// @param got The length actually supplied.
error Truncated(uint256 needed, uint256 got);
/// @notice The recomputed key-block digest does not equal the one the certificate declares, so the keys
/// present are not the keys the issuer attested.
/// @param derived The digest recomputed from the key block.
/// @param declared The digest the certificate carries.
error SubjectKeyIdMismatch(bytes32 derived, bytes32 declared);
/// @notice A stage is missing a key it must carry, or carries half of a pair that is issued whole.
/// @param purpose The purpose whose slot is unfilled.
error MissingSlot(uint16 purpose);
/// @notice A slot carries a key of the wrong scheme. It would verify cryptographically and mean
/// something else entirely, which is exactly what splitting the classes exists to prevent.
/// @param purpose The slot's purpose.
/// @param algorithm The algorithm identifier that was present.
error WrongAlgorithmForSlot(uint16 purpose, uint16 algorithm);
/// @notice Two key entries share one `(purpose, algorithm)` pair, so one would silently shadow the
/// other.
/// @param purpose The repeated purpose.
/// @param algorithm The repeated algorithm identifier.
error DuplicateKey(uint16 purpose, uint16 algorithm);
/// @notice The key entries are not in ascending `(purpose, algorithm)` order. The schema requires that
/// order so `certHash` is reproducible across implementations.
error KeysNotSorted();
/// @notice A signing key whose length is not the one its algorithm defines.
/// @param algorithm The algorithm identifier the entry declares.
/// @param length The key length that was present.
error BadKeyLength(uint16 algorithm, uint256 length);
/// @notice A delegation bound shallower than the certificate's own depth, which admits nothing.
/// @param depth The certificate's position on the delegation axis.
/// @param maxDelegationDepth The deepest level it claims to issue to.
error InvalidDepth(uint8 depth, uint8 maxDelegationDepth);
/// @notice A certificate that expires no later than it begins.
/// @param notBefore The declared start, in the schema's nanoseconds.
/// @param notAfter The declared end, in the schema's nanoseconds.
error ValidityInverted(uint64 notBefore, uint64 notAfter);
/**
* @notice Parse and self-check a `TBSCertificate`.
* @dev Checking for a CAPABILITY rather than a type is the certificate schema's own rule, and the reason
* there is no type field to check instead. Passing the LIVE purposes to a recovery certificate
* finds neither key and reverts — which is what stops a recovery certificate being registered as a
* live one and handing the recovery pair everyday authority.
*
* Self-check means the declared `SubjectKeyId` is recomputed from the key block that follows it and
* compared. That field is inside the TBS and therefore covered by the issuer's signatures, so the
* comparison turns "these bytes decode" into "the issuer attested these exact keys". Doing it on
* chain costs one precompile call and buys a verdict any reader can recompute; gas is not a design
* constraint on the chain this runs on, and must not be traded for a check that would then have to
* be taken on trust from whichever process ran it.
*
* A stage is issued as a unit, so both of a stage's signing keys must be present, and its
* encapsulation pair must be present in full or absent in full.
* @param tbs the TBS bytes, verbatim. Not the whole certificate.
* @param txPurpose the transaction-class purpose this stage should carry.
* @param accessPurpose the access-class purpose for the same stage.
* @param kemPurpose the encapsulation purpose for the same stage, or {NO_KEM_PURPOSE} for a stage that
* has none.
* @return out The parsed certificate: digest, serial, names, key identifiers, depth pair, validity
* window, and every key slot the stage carries.
*/
function parse(bytes calldata tbs, uint16 txPurpose, uint16 accessPurpose, uint16 kemPurpose)
internal
view
returns (Parsed memory out)
{
_need(tbs, 58);
if (uint32(bytes4(tbs[0:4])) != MAGIC) revert BadMagic(uint32(bytes4(tbs[0:4])));
// Both live wire generations parse. An artifact issued under the older one is read rather than
// refused; whether it may be ADMITTED is a separate question, settled at registration by the
// holder's proof of possession and the chain-issuer pins.
uint32 wireVersion = uint32(bytes4(tbs[4:8]));
if (wireVersion != VERSION && wireVersion != VERSION_V4) revert BadVersion(wireVersion);
out.certHash = FinalChainPrecompiles.sha3_256(tbs);
out.serial = bytes32(tbs[8:40]);
out.depth = uint8(tbs[40]);
out.maxDelegationDepth = uint8(tbs[41]);
uint64 notBeforeNs = uint64(bytes8(tbs[42:50]));
uint64 notAfterNs = uint64(bytes8(tbs[50:58]));
if (out.maxDelegationDepth < out.depth) {
revert InvalidDepth(out.depth, out.maxDelegationDepth);
}
if (notAfterNs != 0 && notAfterNs <= notBeforeNs) {
revert ValidityInverted(notBeforeNs, notAfterNs);
}
out.notBefore = notBeforeNs / NS_PER_MILLISECOND;
out.notAfter = notAfterNs == 0 ? 0 : notAfterNs / NS_PER_MILLISECOND;
// Four length-prefixed fields: IssuerDN, SubjectDN, AuthorityKeyId,
// SubjectKeyId. Every field before them is fixed width, which is the
// whole reason the schema orders them this way.
uint256 p = 58;
uint256 issuerDnLen;
(p, issuerDnLen) = _skipLengthPrefixed(tbs, p);
out.issuerDnHash = keccak256(tbs[p - issuerDnLen:p]);
uint256 subjectDnLen;
(p, subjectDnLen) = _skipLengthPrefixed(tbs, p);
out.subjectDn = tbs[p - subjectDnLen:p];
uint256 akidLen;
(p, akidLen) = _skipLengthPrefixed(tbs, p);
out.authorityKeyId = _bytes32At(tbs, p - akidLen, akidLen);
uint256 skidLen;
(p, skidLen) = _skipLengthPrefixed(tbs, p);
uint256 skidStart = p - skidLen;
_need(tbs, p + 2);
uint16 keyCount = uint16(bytes2(tbs[p:p + 2]));
p += 2;
// AFTER the count word. `SubjectKeyId` is SHA3-256 of the KeyEntry
// array alone — `encodeTbs` writes `PublicKeyCount` as its own field and
// `encodePublicKeyBlock` returns only the entries. Hashing the count in
// produces a digest that is self-consistent and matches no certificate
// any issuer ever wrote.
uint256 blockStart = p;
uint32 previousSort = 0;
for (uint256 i = 0; i < keyCount; i++) {
_need(tbs, p + 8);
uint16 alg = uint16(bytes2(tbs[p:p + 2]));
uint16 purpose = uint16(bytes2(tbs[p + 2:p + 4]));
uint32 keyLen = uint32(bytes4(tbs[p + 4:p + 8]));
p += 8;
_need(tbs, p + keyLen);
// Ascending by (purpose, algorithm), duplicates invalid. The schema
// requires the order so `certHash` is reproducible across
// implementations; enforcing it here also means a second entry for
// one slot cannot quietly shadow the first.
uint32 sortKey = (uint32(purpose) << 16) | uint32(alg);
if (i > 0) {
if (sortKey == previousSort) revert DuplicateKey(purpose, alg);
if (sortKey < previousSort) revert KeysNotSorted();
}
previousSort = sortKey;
// The algorithm is pinned per CLASS, not merely recorded. A
// transaction slot carrying an access-class key would verify
// cryptographically and mean something entirely different — an
// identity key must never authorize a transaction, or splitting the
// classes buys nothing.
// Matched on the PAIR, not on the purpose alone. A CA carries two
// keys under one purpose (`0x0004`) distinguished only by
// algorithm, so matching on purpose first would find the first of
// them twice and the second never.
if (purpose == txPurpose && alg == ALG_ML_DSA_87) {
if (keyLen != FinalChainPrecompiles.ML_DSA_87_PUBLIC_KEY_LEN) {
revert BadKeyLength(alg, keyLen);
}
out.transactionKey = tbs[p:p + keyLen];
} else if (purpose == accessPurpose && alg == ALG_SLH_DSA_SHAKE_256S) {
if (keyLen != FinalChainPrecompiles.SLH_DSA_SHAKE_256S_PUBLIC_KEY_LEN) {
revert BadKeyLength(alg, keyLen);
}
out.accessKey = tbs[p:p + keyLen];
} else if (purpose == kemPurpose && alg == ALG_ML_KEM_1024) {
out.kemMlKem = tbs[p:p + keyLen];
} else if (purpose == kemPurpose && alg == ALG_HQC_5) {
out.kemHqc = tbs[p:p + keyLen];
} else if (purpose == PURPOSE_ACTIVE_SEAL && alg == ALG_SLH_DSA_SHAKE_256S) {
if (keyLen != FinalChainPrecompiles.SLH_DSA_SHAKE_256S_PUBLIC_KEY_LEN) {
revert BadKeyLength(alg, keyLen);
}
out.sealKey = tbs[p:p + keyLen];
} else if (purpose == PURPOSE_ACTIVE_SEAL) {
// The seal is hash-based by definition — it exists to stand on
// the OTHER assumption from the transaction key it co-signs
// with. A lattice seal would be two signatures on one bet.
revert WrongAlgorithmForSlot(purpose, alg);
} else if (purpose == txPurpose || purpose == accessPurpose) {
// A slot the caller asked for, carrying the wrong scheme. It
// would verify cryptographically and mean something else
// entirely — an identity key must never authorize a
// transaction, or splitting the classes buys nothing.
revert WrongAlgorithmForSlot(purpose, alg);
} else if (purpose == kemPurpose) {
// Same rule for the encapsulation slot. A third KEM appearing
// under this purpose is a hybrid whose second family nobody
// agreed on, and admitting it silently is how a pair becomes a
// trio that one reader honours and another ignores.
revert WrongAlgorithmForSlot(purpose, alg);
}
// NO length check on the KEM keys here, and that is deliberate.
// The signing slots are checked against a constant because the
// parser's own callers depend on the length; an encapsulation key
// is checked by `0x0203` / `0x0207` at the moment it is REGISTERED,
// where the answer is a well-formedness verdict rather than a
// parse failure. Two checks of the same thing in two shapes is how
// one of them ends up weaker and nobody notices which.
p += keyLen;
}
// `SubjectKeyId` is SHA3-256 of the KeyEntry array, count word
// EXCLUDED — `blockStart` is taken after the count is consumed, for the
// reason given where it is set. Recomputing it is what turns "these
// bytes decode" into "the CA signed these exact keys"; the field is
// inside the TBS, so it is covered by the signatures.
out.subjectKeyId = FinalChainPrecompiles.sha3_256(tbs[blockStart:p]);
bytes32 declared = _bytes32At(tbs, skidStart, skidLen);
if (out.subjectKeyId != declared) revert SubjectKeyIdMismatch(out.subjectKeyId, declared);
// Both or neither. A stage is issued as a unit, so a certificate
// carrying one of its two keys is not a partial certificate — it is a
// certificate for a stage that does not exist.
if (out.transactionKey.length == 0) revert MissingSlot(txPurpose);
if (out.accessKey.length == 0) revert MissingSlot(accessPurpose);
// The encapsulation pair is both-or-neither for the same reason, and
// the reason is louder here: a hybrid quietly reduced to one family is
// identical on the wire, so a certificate carrying only the lattice
// half would seal successfully and silently drop the code-based hedge.
// Neither is the CA case and the pre-v4 case, both legitimate.
if ((out.kemMlKem.length == 0) != (out.kemHqc.length == 0)) {
revert MissingSlot(kemPurpose);
}
_need(tbs, p + 2);
uint16 extCount = uint16(bytes2(tbs[p:p + 2]));
p += 2;
for (uint256 i = 0; i < extCount; i++) {
_need(tbs, p + 7);
uint16 extType = uint16(bytes2(tbs[p:p + 2]));
uint32 valueLen = uint32(bytes4(tbs[p + 3:p + 7]));
p += 7;
_need(tbs, p + valueLen);
// The Institution extension's VALUE, kept for the issuer
// profile's jurisdiction rule. Everything else is skipped as
// before — extensions are structural to certHash, semantic to
// whichever consumer knows them.
if (extType == EXT_INSTITUTION) out.institutionExt = tbs[p:p + valueLen];
p += valueLen;
}
out.tbsLength = p;
}
/// @notice Parse a LIVE-stage certificate: the live transaction and access keys.
/// @dev `external`, like the other three entry points below. The identity registry sits against the
/// deployed-code ceiling and this parser is its single largest inlined dependency, so the four doors
/// it calls are DEPLOY-LINKED: the library is one more contract in the state plane's fixed deploy
/// order, and its address is baked immutably into the registry's bytecode. A linked library is code,
/// not a key — nothing can repoint it after deployment, so the split costs a call boundary and no
/// trust.
/// @param tbs The TBS bytes, verbatim.
/// @return The parsed and self-checked certificate.
function parseLive(bytes calldata tbs) external view returns (Parsed memory) {
return parse(tbs, PURPOSE_ACTIVE_TX, PURPOSE_ACTIVE_ACCESS, PURPOSE_ACTIVE_KEM);
}
/// @notice Parse a RECOVERY-stage certificate.
/// @dev The recovery pair authorizes rotating the wallet's own credentials and NOTHING else. Acting as a
/// guardian is an ordinary action for that account and uses the live access key, so keeping the two
/// stages in separate certificates is what makes that boundary something a verifier can see.
/// @param tbs The TBS bytes, verbatim.
/// @return The parsed and self-checked certificate.
function parseRecovery(bytes calldata tbs) external view returns (Parsed memory) {
return parse(tbs, PURPOSE_RECOVERY_TX, PURPOSE_RECOVERY_ACCESS, PURPOSE_RECOVERY_KEM);
}
/// @notice Parse a certificate authority's certificate, whose two keys are both cert-signing.
/// @dev Both classes resolve to the same purpose, which is why {parse} matches on the
/// `(purpose, algorithm)` PAIR: an authority carries two keys under one purpose and matching on the
/// purpose alone would find the first of them twice and the second never.
/// @dev No encapsulation purpose. An authority signs and is never sealed to, so {NO_KEM_PURPOSE} is
/// passed as a value the key loop can never match. An authority certificate carrying encapsulation
/// keys would parse them into slots the registry then discards, which is a shape worth refusing to
/// have at all.
/// @param tbs The TBS bytes, verbatim.
/// @return The parsed and self-checked certificate.
function parseCa(bytes calldata tbs) external view returns (Parsed memory) {
return parse(tbs, PURPOSE_CERT_SIGNING, PURPOSE_CERT_SIGNING, NO_KEM_PURPOSE);
}
/**
* @notice Verify an issuer's dual signature over a TBS.
* @dev Both must verify, not either. Two signatures under two different hardness assumptions is the
* entire reason a certificate carries two, and accepting one would collapse that to whichever
* family breaks first.
*
* Provided for callers that verify an off-chain issuance against keys they already trust. The
* caller supplies the issuer's keys, so it is the caller's job to have taken them from a registered
* record rather than from its own calldata — a key handed in with the signature proves nothing.
* @param tbs The signed TBS bytes.
* @param issuerMlDsaKey The issuer's registered ML-DSA-87 cert-signing key.
* @param issuerSlhDsaKey The issuer's registered SLH-DSA-SHAKE-256s cert-signing key.
* @param mlDsaSignature The lattice signature over `tbs`.
* @param slhDsaSignature The hash-based signature over `tbs`.
* @return Whether both signatures verify.
*/
function verifyIssuerSignatures(
bytes memory tbs,
bytes memory issuerMlDsaKey,
bytes memory issuerSlhDsaKey,
bytes memory mlDsaSignature,
bytes memory slhDsaSignature
) external view returns (bool) {
return FinalChainPrecompiles.verifyMlDsa87(issuerMlDsaKey, tbs, mlDsaSignature)
&& FinalChainPrecompiles.verifySlhDsa(issuerSlhDsaKey, tbs, slhDsaSignature);
}
/// @notice Refuse a TBS that is shorter than the parser is about to read.
/// @dev Called before every read rather than once at the top, because the layout is variable-length: a
/// certificate can be well-formed up to its key block and truncated inside it, and a parser that
/// only checked the fixed header would read whatever calldata followed.
/// @param tbs The TBS bytes.
/// @param upto The offset the next read needs to be valid.
function _need(bytes calldata tbs, uint256 upto) private pure {
if (tbs.length < upto) revert Truncated(upto, tbs.length);
}
/// @notice Step over one four-byte-length-prefixed field and report where it was.
/// @dev Bounds-checks the prefix before reading it and the value before returning, so a truncated
/// certificate cannot make the cursor run past the end of calldata. The caller recovers the value's
/// slice as `tbs[next - length:next]`.
/// @param tbs The TBS bytes.
/// @param p Offset of the length prefix.
/// @return next Offset just past the field's value.
/// @return length The field's declared length.
function _skipLengthPrefixed(bytes calldata tbs, uint256 p)
private
pure
returns (uint256 next, uint256 length)
{
_need(tbs, p + 4);
length = uint32(bytes4(tbs[p:p + 4]));
next = p + 4 + length;
_need(tbs, next);
}
/// @notice Read a key identifier out of the TBS as one word.
/// @dev Answers `bytes32(0)` for any length other than 32 rather than reverting. A key identifier that
/// is not 32 bytes is not a SHA3-256 digest, so it cannot match the value it is compared against,
/// and the comparison at the call site produces the correct refusal with no separate error to
/// define. The one legitimate short case is a zero-length authority key identifier, which the
/// caller must reject on its own terms.
/// @param tbs The TBS bytes.
/// @param start Offset of the field's value.
/// @param length The field's declared length.
/// @return The 32-byte value, or zero when the field is not 32 bytes long.
function _bytes32At(bytes calldata tbs, uint256 start, uint256 length)
private
pure
returns (bytes32)
{
// A SubjectKeyId that is not 32 bytes is not a SHA3-256 digest, so it
// cannot match and the comparison will fail — which is the correct
// outcome and needs no separate error.
if (length != 32) return bytes32(0);
return bytes32(tbs[start:start + 32]);
}
}
contracts/finalchain/FinalChainPrecompiles.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may link this library into contracts deployed on a
// Final DeFi Protocol chain in order to reach that chain's hash and
// post-quantum signature-verification precompiles.
// 2. Integrators, node operators, and auditors may use it to reproduce and
// independently re-verify any verdict those precompiles produced, as part of
// their integration with the Final DeFi Protocol.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this library or a competing state plane derived
// from it without permission prior to the Change Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
/**
* @title Final Chain Precompiles
* @notice The three primitives Final Chain adds to the EVM, and the only
* supported way to reach them.
*
* @dev **These exist ONLY on Final Chain (chain id 48359).** They are provided
* by this chain's own node binary, and
* nothing at these addresses on Ethereum, Optimism or any other chain will
* answer. A contract that calls them must be one that only ever runs here;
* `assertAvailable` below is the cheap way to fail loudly rather than treat an
* empty return as a verified signature.
*
* The addresses are the FIPS numbers, which is the whole allocation rule —
* there is no local registry to consult and no way for two implementations to
* disagree about where a primitive lives:
*
* | address | primitive | FIPS |
* |---|---|---|
* | `0x…0202` | SHA3-256 | 202 |
* | `0x…0203` | ML-KEM-1024 key validation | 203 |
* | `0x…0204` | ML-DSA-87 verify | 204 |
* | `0x…0205` | SLH-DSA-SHAKE-256s verify | 205 |
* | `0x…0207` | HQC-5 key validation | 207 |
*
* The two KEM addresses VALIDATE keys and do nothing else, for one reason:
* encapsulation is a SENDER operation and decapsulation needs the secret key,
* so neither belongs on a chain at all. Checking that a registered public key
* is well-formed is hardening rather than a dependency, and nothing in this
* system waits on it.
*
* HQC's number is 207. It had none when the KEM pair was chosen, which was the
* one thing separating it from ML-KEM here — a primitive with no standard
* number has no address under this rule, and inventing one would have been a
* local convention masquerading as the global one.
*
* **No AEAD precompile, at any number.** The chain must never be able to
* decrypt an intent, and checking a revealed body against its commitment is a
* hash compare that `0x0202` already serves.
*
* ## Why this library refuses to take a public key from its caller
*
* It does take one — the primitives are pure functions and cannot do otherwise.
* The rule lives one level up, in `FinalPqQuorum`: a key passed as an argument
* proves nothing, because anyone holding a keypair can produce a valid
* signature under it. Only a key read from `FinalIdentityRegistry` is evidence
* about WHO signed. Every call site here must be able to answer "where did this
* key come from" with "storage", never "calldata".
*
* ## `success` is not the answer
*
* A `staticcall` to a verifier returns two things and both matter. `success`
* false means the call was malformed — usually a length bug in the caller — and
* `success` true with a zero word means the signature did not verify. The
* helpers below collapse both to `false` for the caller's convenience, which is
* safe in that direction and only in that direction: treating a failed call as
* a valid signature would be the whole security of the system.
*/
library FinalChainPrecompiles {
/// @notice SHA3-256 (FIPS 202). NOT `keccak256`, which is the
/// pre-standardisation padding and produces a different digest.
address internal constant SHA3_256 = address(0x0202);
/// @notice ML-DSA-87 verification (FIPS 204). Transaction-class keys.
address internal constant ML_DSA_87 = address(0x0204);
/// @notice SLH-DSA-SHAKE-256s verification (FIPS 205). Access-class keys.
address internal constant SLH_DSA_SHAKE_256S = address(0x0205);
/// @notice ML-KEM-1024 encapsulation-key validation (FIPS 203).
/// @dev VALIDATES; it does not encapsulate. Runs FIPS 203 §7.2's own
/// encapsulation-key check — the type check and the modulus check — and
/// nothing else. Encapsulation is a sender operation and decapsulation
/// needs the secret key, so neither belongs on a chain.
address internal constant ML_KEM_1024 = address(0x0203);
/// @notice HQC-5 public-key validation (FIPS 207).
/// @dev Structural only: the length, and the three padding bits the
/// encoding leaves beyond `n = 57637`. HQC has no cheap key-validity
/// predicate and this does not pretend to one.
address internal constant HQC_5 = address(0x0207);
/// @notice ML-DSA-87 public key length. Round-3 Dilithium5 shares it.
uint256 internal constant ML_DSA_87_PUBLIC_KEY_LEN = 2592;
/// @notice ML-DSA-87 signature length. Round-3 Dilithium5 is 4595.
uint256 internal constant ML_DSA_87_SIGNATURE_LEN = 4627;
/// @notice SLH-DSA-SHAKE-256s public key length (`PK.seed ‖ PK.root`).
uint256 internal constant SLH_DSA_SHAKE_256S_PUBLIC_KEY_LEN = 64;
/// @notice SLH-DSA-SHAKE-256s signature length. The `f` set is 49,856.
uint256 internal constant SLH_DSA_SHAKE_256S_SIGNATURE_LEN = 29792;
/// @notice Thrown when a precompile is absent, i.e. this is not Final Chain
/// or the node is stock reth rather than `final-reth`.
error PrecompileUnavailable(address precompile);
/**
* @notice Reverts unless all five precompiles answer.
* @dev Call this from a constructor. A contract whose security rests on PQ
* verification must not deploy onto a chain that cannot perform it — the
* failure mode otherwise is a quorum that reaches threshold with zero valid
* signatures, discovered at the worst possible moment.
*
* The probe is SHA3-256 of the empty string, whose value is a published
* FIPS 202 constant. It cannot be produced by an address with no code
* (which returns empty) nor by `keccak256` (which gives a different digest
* for the same input), so it distinguishes "the right precompile" from both
* "nothing here" and "the wrong hash function".
*/
function assertAvailable() internal view {
bytes32 expected = 0xa7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a;
(bool ok, bytes memory out) = SHA3_256.staticcall("");
if (!ok || out.length != 32 || bytes32(out) != expected) {
revert PrecompileUnavailable(SHA3_256);
}
// The two signature verifiers are probed by shape rather than by a
// known-answer vector: a KAT here would put a 29,792-byte signature in
// this contract's bytecode. A deliberately short input is a
// *precompile error* by contract, so a FAILED call is the pass and a
// silent success would mean something else is answering at the address.
_probeRejectsShortInput(ML_DSA_87);
_probeRejectsShortInput(SLH_DSA_SHAKE_256S);
// The two KEM validators are probed the other way round, because they
// are total by contract: a wrong length is a malformed KEY, which is
// the question being asked, so they ANSWER rather than error. A
// one-byte input must therefore come back as a well-formed `false`, and
// a failed call means nothing is there.
_probeAnswersFalse(ML_KEM_1024);
_probeAnswersFalse(HQC_5);
}
/**
* @dev A short input must make the precompile ERROR. The gas budget is the
* whole subtlety.
*
* A reverting CONTRACT refunds the gas it did not use. A precompile that
* returns an error consumes **everything forwarded to it** — and Solidity
* forwards 63/64 of what is left by default. Two such probes in a
* constructor therefore burn all but 1/4096 of the deployment's gas, and
* the deploy fails with no revert data at all.
*
* That is not hypothetical: it is what happened the first time this ran
* against a real `final-reth`, and no Foundry test could have caught it.
* A mocked precompile is a contract, and a contract's `require` hands the
* gas back.
*
* 5,000 is generous for a call that fails on a length check before any
* cryptography runs, and small enough that both probes together are noise
* against a deployment.
*/
function _probeRejectsShortInput(address precompile) private view {
bool ok;
assembly ("memory-safe") {
let ptr := mload(0x40)
mstore8(ptr, 0x00)
ok := staticcall(5000, precompile, ptr, 0x01, 0x00, 0x00)
}
if (ok) revert PrecompileUnavailable(precompile);
}
/**
* @dev A one-byte input must come back as a well-formed zero word.
*
* The inverse of `_probeRejectsShortInput`, and the inversion is the point:
* these two precompiles are TOTAL. Every byte string has an answer to "is
* this a well-formed key", and for one byte the answer is no. A precompile
* that errored here would be one that treats a malformed key as a caller
* bug, which is the opposite of what a registry wants.
*
* Gas is bounded for the same reason as the other probe — an erroring
* precompile consumes everything forwarded — even though the pass case
* returns normally and refunds.
*/
function _probeAnswersFalse(address precompile) private view {
bool ok;
bytes32 answer;
assembly ("memory-safe") {
let ptr := mload(0x40)
mstore8(ptr, 0x00)
ok := staticcall(5000, precompile, ptr, 0x01, ptr, 0x20)
answer := mload(ptr)
}
if (!ok || answer != bytes32(0)) revert PrecompileUnavailable(precompile);
}
/**
* @notice Is `encapsulationKey` a well-formed ML-KEM-1024 key?
*
* @dev The check a registry owes a sender. A malformed encapsulation key
* stored on chain is an account whose intents cannot be sealed, and the
* discovery happens at the first attempt to seal one — on the hybrid path,
* as a pair silently reduced to one family, which is the failure with no
* error attached.
*
* False rather than reverting on any shape, including the wrong length,
* because the caller is asking a question and every input has an answer.
*/
function isWellFormedMlKem1024(bytes memory encapsulationKey) internal view returns (bool) {
return _validatesKey(ML_KEM_1024, encapsulationKey);
}
/// @notice Is `publicKey` a well-formed HQC-5 key?
/// @dev Structural, and honestly partial — see the precompile. It catches a
/// truncated key, a key from the wrong parameter set, and a tail carrying
/// smuggled bytes, which are the three ways this goes wrong in practice.
function isWellFormedHqc5(bytes memory publicKey) internal view returns (bool) {
return _validatesKey(HQC_5, publicKey);
}
/// @dev A failed CALL is not a false answer. It means nothing is at the
/// address — this is not Final Chain, or the node is stock reth — and
/// reading it as "the key is malformed" would silently disable the check on
/// exactly the deployment where it cannot run.
function _validatesKey(address precompile, bytes memory key) private view returns (bool) {
(bool ok, bytes memory out) = precompile.staticcall(key);
if (!ok || out.length != 32) revert PrecompileUnavailable(precompile);
return bytes32(out) != bytes32(0);
}
/// @notice FIPS 202 SHA3-256 over `data`.
/// @dev The certificate schema hashes `TBSCertificate`, `SubjectKeyId` and
/// `AuthorityKeyId` with this, so it is the only function that can check a
/// `certHash` against the bytes it claims to summarise.
function sha3_256(bytes memory data) internal view returns (bytes32 digest) {
(bool ok, bytes memory out) = SHA3_256.staticcall(data);
if (!ok || out.length != 32) revert PrecompileUnavailable(SHA3_256);
digest = bytes32(out);
}
/// @notice Verify an ML-DSA-87 signature. False on any failure, including
/// a malformed call.
function verifyMlDsa87(bytes memory publicKey, bytes memory message, bytes memory signature)
internal
view
returns (bool)
{
if (
publicKey.length != ML_DSA_87_PUBLIC_KEY_LEN
|| signature.length != ML_DSA_87_SIGNATURE_LEN
) return false;
return _verify(ML_DSA_87, publicKey, signature, message);
}
/// @notice Verify an SLH-DSA-SHAKE-256s signature. False on any failure.
function verifySlhDsa(bytes memory publicKey, bytes memory message, bytes memory signature)
internal
view
returns (bool)
{
if (
publicKey.length != SLH_DSA_SHAKE_256S_PUBLIC_KEY_LEN
|| signature.length != SLH_DSA_SHAKE_256S_SIGNATURE_LEN
) return false;
return _verify(SLH_DSA_SHAKE_256S, publicKey, signature, message);
}
/// @dev `publicKey ‖ signature ‖ message`, in that order. Both fixed-length
/// fields come first so the message is unambiguously the remainder — the
/// same reason the precompile takes no length prefix.
function _verify(
address precompile,
bytes memory publicKey,
bytes memory signature,
bytes memory message
) private view returns (bool) {
(bool ok, bytes memory out) =
precompile.staticcall(abi.encodePacked(publicKey, signature, message));
return ok && out.length == 32 && bytes32(out) != bytes32(0);
}
}
contracts/finalchain/FinalChainTime.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may link this time library into contracts deployed on
// a Final DeFi Protocol chain, and may read its constants to interpret the
// timestamps and durations that chain publishes.
// 2. Integrators, indexers, and operators may use it to convert between this
// chain's clock and the units their own systems keep, as part of their
// integration with the Final DeFi Protocol.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this library or a competing state plane derived
// from it without permission prior to the Change Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
/**
* @title Final Chain Time
* @notice **On this chain, `block.timestamp` is MILLISECONDS, not seconds.**
* @dev Every other EVM chain stamps seconds. This one cannot. It mints a block every 100 ms, and the protocol
* requires block timestamps to strictly increase, so a second-denominated clock would exhaust its distinct
* values ten times over per second. Milliseconds is the deliberate consequence, and it is a property of the
* CHAIN itself rather than of any contract here — nothing in this library can change it, and nothing deployed
* beside this library may assume otherwise.
*
* Every duration and every instant on this chain is therefore in milliseconds. This library exists so that fact
* is stated in one place and converted in one place, instead of being assumed independently everywhere a
* deadline or a delay is written.
*
* ## The naming rule, which is a safety rule
*
* A field or constant carrying a duration or an instant on this chain ends in `Ms`. This is not decoration. A
* delay field named for seconds while holding milliseconds elapses a thousand times too fast: a one-day
* recovery delay would mature in about eighty-six seconds, and a two-year dormancy threshold in under a day.
* Those delays are the whole of what stands between a stolen credential and an account, so a name that states
* the wrong unit is not a cosmetic defect — it is the defect, wearing a disguise. `Seconds`-suffixed names do
* not appear in this directory and must not be introduced.
*
* A test harness is not a check on this. Standard EVM tooling stamps `block.timestamp` in seconds, so a suite
* can agree with the contracts under test and both be wrong about the chain they deploy to. The unit has to be
* carried by the names.
*
* Solidity's `hours` and `days` suffixes remain the clearest way to write a duration, so durations are written
* as `24 hours * MS_PER_SECOND` rather than as a bare literal: the intent stays readable and the unit stays
* explicit at the point of use.
*/
library FinalChainTime {
/// @notice Milliseconds per second — the whole conversion between this chain's clock and ordinary time,
/// named once.
/// @dev Multiply a `seconds`-denominated Solidity duration literal by this to express it in this chain's
/// units. It is deliberately the only place the factor appears.
uint64 internal constant MS_PER_SECOND = 1_000;
/// @notice Nanoseconds per millisecond — the divisor for values that arrive stamped in nanoseconds.
/// @dev The certificate schema stamps validity windows in nanoseconds, so a certificate converts DOWN to
/// this chain's clock. Dividing rather than multiplying is the direction that cannot overflow, and it
/// truncates toward the past, which for a validity window is the conservative rounding.
uint64 internal constant NS_PER_MILLISECOND = 1_000_000;
/// @notice This chain's current time, in milliseconds.
/// @dev A function rather than a bare `block.timestamp` read so the unit is visible at every call site.
/// It performs no arithmetic and exists purely so that reading the clock is self-describing, where
/// `block.timestamp` on this chain is silently a thousand times what a reader would assume.
/// @return nowInMs The current block's timestamp, in milliseconds.
function nowMs() internal view returns (uint64) {
return uint64(block.timestamp);
}
}
contracts/finalchain/FinalIdentityRegistry.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may deploy this identity registry as part of a Final
// DeFi Protocol state plane, and may register, rotate, and revoke identity
// records in it under the authority this contract enforces.
// 2. Operators, integrators, and end users may read the certificates, public
// keys, role bits, and signer bindings it holds, and may call its views to
// resolve an identity, a sender, or a quorum roster.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this identity registry or a competing certificate
// authority derived from it without permission prior to the Change Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
import {FinalCertificate} from "./FinalCertificate.sol";
import {FinalChainTime} from "./FinalChainTime.sol";
import {FinalChainPrecompiles} from "./FinalChainPrecompiles.sol";
import {FinalPqQuorum} from "./FinalPqQuorum.sol";
import {FinalSweep} from "../utils/FinalSweep.sol";
/// @dev Commitment space for one stage's encapsulation pair.
/// Byte-equal to `FinalWalletFactory.DOMAIN_KEM_BUNDLE` and to the certificate issuer's own preimage
/// constant. Three independent derivations of one word: a mismatch in any of them is a certificate that
/// verifies nowhere, so the value is pinned by test against the other two rather than imported.
bytes32 constant DOMAIN_KEM_BUNDLE = keccak256("FINAL_KEM_BUNDLE_v01");
/// @dev Commitment space for the identity tree's wallet leaf.
/// Byte-equal to `IdentityRootModule.DOMAIN_IDENTITY_LEAF` on every execution chain. Restated rather
/// than imported because that module lives on other chains and no import would make the two one value; a
/// cross-contract parity test pins the pair. The spelling is FROZEN: the premined certificates were mined
/// against this exact constant, and the leaf it derives is the `certHash` inside a wallet's address
/// derivation, so changing a byte here moves addresses that already exist.
bytes32 constant DOMAIN_IDENTITY_LEAF = keccak256("FINAL_IDENTITY_LEAF_PQ_v01");
/// @dev Commitment space for the identity tree's ISSUER leaf.
/// An issuer projects under its own domain — `DOMAIN_ISSUER_LEAF ‖ certHash ‖ version ‖
/// issuerTreeRoot` — so an issuer record is stapleable for offline licence verification while the distinct
/// domain keeps it out of wallet admission: an execution chain's gateway folds with the wallet domain, so an
/// issuer leaf can never satisfy an identity-certificate check there. `issuerTreeRoot` is a RESERVED word,
/// zero until an issuer's own certificate-tree anchor is wired — the only clean path to offline licence
/// revocation, since fixed-depth insertion-ordered state trees cannot prove non-inclusion.
bytes32 constant DOMAIN_ISSUER_LEAF = keccak256("FINAL_ISSUER_LEAF_v01");
/// @dev The issuer name every chain-attested certificate carries, as a keccak digest.
/// The chain is the issuer but holds no keypair, so a chain-attested certificate carries this named
/// value in its issuer field: required by the wire format, verifying nothing on its own, and covered by
/// `certHash`. The name is deliberately environment-agnostic and jurisdiction-silent — the issuer is the
/// worldwide network rather than a legal entity, and an environment-specific name would fork `certHash` per
/// environment. Compared as a hash rather than as a string, so the check costs one word.
bytes32 constant CHAIN_ISSUER_DN_HASH = keccak256("CN=Final Chain,O=Final DeFi");
/// @dev The authority key identifier every chain-attested certificate names.
/// `SHA3-256(utf8("FINAL_CHAIN_AUTHORITY_v01"))` — a DOMAIN constant rather than the digest of a key,
/// because the chain issues certificates and holds no public key block to hash. Precomputed rather than
/// derived at construction: the harness the unit tests run under does not implement the real SHA3 function,
/// and the literal is pinned by test against a reference implementation. A zero-length authority key
/// identifier is reserved and is admitted nowhere.
bytes32 constant CHAIN_AUTHORITY_KEY_ID =
0x9a6a5d8139ad2d28957698330aaa691017dba7dc80eb7cbec585239fb680bbab;
/**
* @title Identity Leaf Sink
* @notice The identity tree's projection door on the state-trees contract.
* @dev A narrow interface rather than an import, because the trees contract imports THIS file — the
* dependency runs that way, and this is the one call that runs the other. Declaring the single method
* here keeps the cycle away from the compiler without duplicating either contract's surface.
*/
interface IIdentityLeafSink {
/// @notice Recompute and store the identity-tree leaf for each named account.
/// @dev Called inside the same transaction as every identity mutation, so an execution chain's admission
/// set sees a registration, rotation or revocation the moment this chain does. The leaf VALUE is
/// derived by the trees contract from the registry's post-mutation state, so the caller supplies
/// accounts and never a leaf.
/// @param accounts The accounts whose leaves are stale.
function syncIdentityLeaves(address[] calldata accounts) external;
}
/**
* @title Revocation Recorder
* @notice The revocation log's recording door.
* @dev Same narrow-interface reasoning as the leaf sink above. `recorded` is read first, so a fingerprint
* somebody already recorded through the log's permissionless door cannot revert the registry mutation
* that feeds it.
*/
interface IRevocationRecorder {
/// @notice Fold a permanently retired signer fingerprint into the revocation log.
/// @dev The log applies its own permanence gate, reading this registry back; the call states nothing the
/// registry has not already decided.
/// @param signerId The fingerprint that has lost standing for good.
function record(bytes32 signerId) external;
/// @notice Whether the log already holds `signerId`.
/// @param signerId The fingerprint to look up.
/// @return Whether a leaf for it exists.
function recorded(bytes32 signerId) external view returns (bool);
}
/**
* @title Final Identity Registry
* @notice Who every party in the system is, on chain: one record per party, carrying its certificate and its
* actual public keys.
* @dev Every service, every co-signer, every certificate authority and every operator has one record here.
* The record holds the party's public keys in full rather than commitments to them, and this contract is
* the certificate authority as well as the roster.
*
* ## Where this runs
*
* Only on this project's own reth-based chains. Verification happens inside precompiles that exist
* nowhere else: SHA3-256 at `0x0202`, ML-DSA-87 at `0x0204` and SLH-DSA-SHAKE-256s at `0x0205`, each
* address being that primitive's FIPS number. The constructor probes them and refuses to deploy where
* they are absent, so a registry of keys the chain cannot check never comes into existence. This
* contract takes part in no CREATE2 derivation — its address is per chain, and nothing derives an
* address from it — and nothing outside this directory imports it.
*
* Gas is deliberately NOT a design constraint on that chain and must not be optimised for. Where a
* choice below trades gas for a verdict that is re-derivable from public state, the verdict wins: a
* signature checked in a precompile is a fact anyone can recompute, where the same check run in a
* library by whichever process happened to hold the keys is only a claim.
*
* ## Keys are read from STORAGE, never from calldata
*
* A commitment would be a quarter of the storage and would be enough to CHECK a key someone hands you.
* It is not enough to VERIFY A SIGNATURE, because verification needs the key itself — and a key that
* arrives in calldata proves nothing, since anyone holding a keypair can produce a valid signature under
* it. A quorum built on caller-supplied keys is a quorum of one: whoever built the calldata.
*
* So the keys live here in full. `FinalPqQuorum` resolves a member through this registry and reads that
* member's key from this registry's storage, and "which key is co-signer three" has exactly one answer,
* in exactly one place. That is the load-bearing rule of every quorum on the chain, not an optimisation.
*
* ## The certificate is the record, not a pointer to one
*
* `certHash` is `SHA3-256(TBSCertificate)`: the certificate's own identity, and the handle revocation is
* keyed on. {registerWallet} and {registerIssuer} take the certificate's TBS bytes and read everything
* out of them — the digest, the serial, the key identifiers, the depth pair, the validity window and
* every public key. Neither takes a key argument, so no two arguments can disagree and no registrar can
* bind a certificate to a keypair that certificate does not contain.
*
* ## The root is the first record here, not a self-signed file
*
* This chain is the only root certificate authority, and the root is pinned as an entry in this registry
* rather than distributed as a self-signed certificate somebody has to install. Chain validation
* terminates here BY IDENTITY. Everything registered after the root is verified on chain, inside the
* precompiles, against what this registry already holds: the holder's own two signatures over the
* admission digest, the pinned chain-issuer constants, and — for a nested issuer — lineage to a
* registered parent whose depth admits it. There is no path by which a key enters this registry
* unattested; a registrar cannot register anything else.
*
* ## Roles are a bitmask
*
* One party is legitimately several things: a co-signer that also publishes, an operator that is also a
* guardian. A single enum would force either duplicate records for one key, which is two sources of
* truth about one party, or a role hierarchy nobody agrees on. A mask has neither problem, and a quorum
* asks whether an account CARRIES a capability rather than whether it IS a type.
*
* ## Membership is hybrid-gated
*
* Who is in this registry, and with which roles, is the root of every quorum on the chain, so it is the
* one thing no single key may decide. Once bootstrap is sealed, every membership mutation — register,
* roles, revoke, a hash-based signing key, the registrar threshold itself — and every state-plane
* configuration change routed through {requireRegistrarQuorum} takes a `ROLE_REGISTRAR` quorum whose
* approvals carry BOTH families: the ML-DSA-87 vote and the SLH-DSA seal. A lattice break cannot then
* rewrite the roster, and neither can a hash-function break; only both at once.
*
* The bootstrap window is the only exception. While it is open the bootstrap admin writes alone, because
* every roster has to be installed by someone before it can install itself. {sealBootstrap} closes it
* irreversibly, and refuses to close it onto a registrar quorum that cannot be met.
*
* ## The sender is not the account
*
* Transactions on this chain are signed by ML-DSA-87, and the node derives `msg.sender` from the key as
* `keccak256(0x04 ‖ publicKey)[12:]`. That address pays gas and holds no authority. {accountOfSender}
* binds it to the identity whose live transaction key it derives from, so a `msg.sender` gate anywhere
* on this chain asks {senderHasRole} and resolves to the identity — and a key rotation moves the binding
* instead of the roster.
*
* ## What this contract deliberately does not do
*
* It never un-revokes: a revoked certificate is finished, and reversing that would reopen every past
* verification. It never enumerates a mapping inside a mutation — the registrars supply the chain list a
* revocation touches, and a fingerprint an incomplete list missed stays permanently recordable through
* the revocation log's own permissionless door. It holds no funds, exposes no payable entrypoint, and
* reserves nothing against a sweep. And it grants no capability by parsing one: a certificate says which
* keys a party holds, `roles` says what the party may do, and the two arrive as different arguments on
* purpose.
*/
contract FinalIdentityRegistry is FinalSweep {
// ---------------------------------------------------------------- roles
/// @notice May co-sign account-state rounds (tree 1).
uint256 public constant ROLE_ACCOUNT_COSIGNER = 1 << 0;
/// @notice May co-sign MMR / bundle-log advances.
uint256 public constant ROLE_MMR_COSIGNER = 1 << 1;
/// @notice May publish PHI ledger state (tree 2).
uint256 public constant ROLE_PHI_PUBLISHER = 1 << 2;
/// @notice May publish vAsset state (tree 3).
uint256 public constant ROLE_VASSET_PUBLISHER = 1 << 3;
/// @notice May publish oracle data (tree 4).
uint256 public constant ROLE_ORACLE_PUBLISHER = 1 << 4;
/// @notice May publish settlement / asset registry roots (trees 5 and 6).
uint256 public constant ROLE_REGISTRY_PUBLISHER = 1 << 5;
/// @notice May act as a wallet guardian.
uint256 public constant ROLE_GUARDIAN = 1 << 6;
/// @notice May submit transactions on behalf of the protocol.
uint256 public constant ROLE_RELAYER = 1 << 7;
/// @notice May register and revoke identities once bootstrap is sealed.
uint256 public constant ROLE_REGISTRAR = 1 << 8;
/// @notice A certificate authority — the root, or an intermediate under it.
uint256 public constant ROLE_CERTIFICATE_AUTHORITY = 1 << 9;
/// @notice May co-sign `FinalSettlementLog` appends — the cross-chain
/// settlement quorum, the same members whose LMS keys satisfy the
/// execution chains' settlement set. A role of its own rather than a
/// second use of `ROLE_REGISTRY_PUBLISHER`: the registries (trees 5/6)
/// change on listing cadence and settlement leaves release custody, and
/// one role for both would put the value plane behind the listing roster.
uint256 public constant ROLE_SETTLEMENT_COSIGNER = 1 << 10;
// ----------------------------------------------------- action domains
/// @notice Action domain for registering or rotating a wallet identity.
/// @dev One domain per membership mutation, so an approval to grant a role can never be replayed as one
/// to revoke. This registry is its own verifying contract for all of these, and the digest also
/// binds a per-contract counter, so an approval authorises exactly one action once.
bytes32 public constant DOMAIN_REGISTER_WALLET = keccak256("FINAL_REGISTRY_REGISTER_WALLET_v01");
/// @notice Action domain for registering or rotating an issuer.
bytes32 public constant DOMAIN_REGISTER_ISSUER = keccak256("FINAL_REGISTRY_REGISTER_ISSUER_v01");
/// @notice The admission proof-of-possession digest domain.
/// @dev The HOLDER signs `keccak256(abi.encode(domain, chainid, registry, certHash, recoveryCertHash,
/// gateNonce))` with the live transaction key (ML-DSA-87) AND the live access key
/// (SLH-DSA-SHAKE-256s) — both families, in the admission transaction, verified by the precompiles.
/// Possession lives in the TRANSACTION, never in the artifact, so holding a copy of somebody's
/// public certificate admits nothing.
bytes32 public constant DOMAIN_IDENTITY_ADMISSION = keccak256("FINAL_IDENTITY_ADMISSION_v01");
/// @notice Action domain for root-plane global certificate revocation, by handle.
bytes32 public constant DOMAIN_REVOKE_CERTIFICATE =
keccak256("FINAL_REGISTRY_REVOKE_CERTIFICATE_v01");
/// @notice Digest domain for an issuer revoking a certificate it signed off chain.
/// @dev Signed by the issuer's own registered cert-signing keys rather than approved by a quorum, and
/// bound to the issuer's own gate nonce, so one issuer's revocations cannot be replayed as
/// another's.
bytes32 public constant DOMAIN_ISSUER_CERT_REVOCATION =
keccak256("FINAL_ISSUER_CERT_REVOCATION_v01");
/// @notice Action domain for recording an account's hash-based signing key.
bytes32 public constant DOMAIN_REGISTER_LMS_KEY = keccak256("FINAL_REGISTRY_REGISTER_LMS_KEY_v01");
/// @notice Action domain for replacing an identity's capability bitmask.
bytes32 public constant DOMAIN_SET_ROLES = keccak256("FINAL_REGISTRY_SET_ROLES_v01");
/// @notice Action domain for retiring an identity.
bytes32 public constant DOMAIN_REVOKE = keccak256("FINAL_REGISTRY_REVOKE_v01");
/// @notice Action domain for moving the registrar threshold itself.
bytes32 public constant DOMAIN_SET_REGISTRAR_THRESHOLD =
keccak256("FINAL_REGISTRY_SET_REGISTRAR_THRESHOLD_v01");
/// @notice The algorithm identifier the sender derivation is domain-separated by.
/// @dev ML-DSA-87, FIPS 204 — the only algorithm this chain's transaction envelope admits. Prefixing it
/// means a key of another family can never derive the same sender address.
uint8 private constant ENVELOPE_ALG_ML_DSA_87 = 4;
// ------------------------------------------------------------- storage
/**
* @title Identity
* @notice One party's on-chain identity.
* @dev `version` increments on every mutation, and that increment is what a rotation IS: the record is
* replaced rather than appended to, and the version is how a reader on another chain knows which of
* two copies it has seen is newer.
*/
struct Identity {
/// SHA3-256 of the LIVE certificate's TBS bytes. The revocation handle.
bytes32 certHash;
/// SHA3-256 of the RECOVERY certificate's TBS bytes.
bytes32 recoveryCertHash;
/// The certificate's 32-byte serial, `16 B entropy ‖ 16 B counter`.
bytes32 serial;
/// SHA3-256 of this certificate's public key block. A child names it in
/// its own `AuthorityKeyId`, which is how the chain links the two.
bytes32 subjectKeyId;
/// Capability bitmask. Zero for a registered-but-idle party.
uint256 roles;
/// Position on the delegation axis; 0 is the Final Chain root.
uint8 depth;
/// Deepest level this key may issue to. `== depth` means it signs no
/// certificates at all, which is every end entity.
uint8 maxDelegationDepth;
/// Milliseconds since the epoch, on this chain's clock. The certificate schema stamps validity in
/// nanoseconds and the parser converts on the way in, so nothing here ever compares across units.
uint64 notBefore;
/// Milliseconds since the epoch, or 0 for "never expires" — which the certificate schema allows and
/// personal identity certificates use. The bound is exclusive.
uint64 notAfter;
/// Monotonic. A rotation that does not advance it is refused.
uint64 version;
/// Set by `revoke`. Never unset: a revoked certificate is finished, and
/// an un-revoke would make every past verification re-openable.
bool revoked;
/// Distinguishes "no record" from "a record whose fields are all zero".
bool registered;
}
/**
* @title Lms Key
* @notice A hash-based (LMS) signing key held by a registered account.
* @dev The execution chains' quorums verify LMS rather than ML-DSA, because those chains have no
* post-quantum precompiles and check a keccak hash chain instead. Those keys are the authority over
* the post-quantum anchor, and therefore over post-quantum execution — which makes "who holds this
* fingerprint?" a question the state plane has to be able to answer, exactly as it answers it for
* every other key.
*
* Recorded against an account that is ALREADY registered, so an LMS key is a capability of a known
* identity rather than a standalone credential. It inherits that identity's revocation: a revoked
* account's signer is a revoked signer, with nothing extra to remember to do.
*/
struct LmsKey {
/// `I`, hashed into every step of the signature.
bytes16 keyId;
/// Merkle tree height. Bound into the fingerprint, because the leaf
/// commits to node `2^h + q` and a signer who could vary it could vary
/// the numbering.
uint8 height;
/// `T[1]`, the LMS public key.
bytes32 root;
/// Monotonic. A rotation that does not advance it is refused, so a
/// replayed registration cannot reinstate a superseded key.
uint64 version;
/// Distinguishes "no key" from "a key whose fields are all zero".
bool registered;
}
/// @notice The hash-based (LMS) signing key an account holds, per chain.
/// @dev One slot per account AND chain. A single-use hash-based counter is a complete defence only while
/// the key it names signs for ONE chain, so the roster is stored the way it is armed: the same
/// operator is a different signer on every chain, and a rotation on one says nothing about another.
mapping(address account => mapping(uint64 chainId => LmsKey)) private _lmsKey;
/**
* @title Lms Binding
* @notice What a signer fingerprint is bound to: the account holding it and the chain it signs for.
* @dev Two fields in one slot, deliberately. This contract sits within a few bytes of the deployed-code
* ceiling, so anything added to this surface has to pay for itself in bytecode first — which is why
* checks that no authority consults, such as refusing a zero chain identifier, are left to the
* publisher off chain rather than spent here.
*/
struct LmsBinding {
/// The account that registered the fingerprint. Zero means no account ever did.
address account;
/// The chain that registration was for. Zero alongside a zero account, for a fingerprint never
/// registered.
uint64 chainId;
}
/// @notice Which account a signer fingerprint belongs to, and which chain it signs for.
/// @dev The lookup the whole LMS record exists for: an execution chain's roster names fingerprints and
/// nothing else, so without this the keys behind those names are unattributable. Written once at
/// registration and left in place when the key is superseded, because attribution is history — a
/// signature made under a retired key was still made by that operator.
///
/// The chain it names is what selects the slot {lmsSignerIsLive} resolves the fingerprint against.
mapping(bytes32 signerId => LmsBinding) private _lmsBinding;
/// @notice The identity record for an account.
mapping(address account => Identity) private _identity;
/// @notice The live transaction key, ML-DSA-87: spending, and every high-cadence protocol action.
/// @dev All four key slots are stored in FULL rather than as commitments, because the precompiles verify
/// against a KEY and a key that arrived in calldata proves nothing about who signed. This is the
/// rule every quorum on this chain rests on.
/// @dev A certificate authority has two keys rather than four, and they live in the two active slots.
/// One storage shape rather than two, because every reader would otherwise have to know which kind
/// of party it was looking at before it could look.
mapping(address account => bytes) private _activeTransactionKey;
/// @notice The live access key, SLH-DSA-SHAKE-256s: identity, rotation and guardianship.
mapping(address account => bytes) private _activeAccessKey;
/// @notice The pre-committed recovery transaction key, ML-DSA-87. Empty for a certificate authority.
mapping(address account => bytes) private _recoveryTransactionKey;
/// @notice The pre-committed recovery access key, SLH-DSA-SHAKE-256s. Empty for a certificate
/// authority.
mapping(address account => bytes) private _recoveryAccessKey;
/// @notice The seal key: a service's second SLH-DSA-SHAKE-256s key, which co-signs execution-class
/// quorum decisions.
/// @dev Empty for every identity whose certificate carries no seal slot, which is every user wallet and
/// every certificate authority. An identity with no seal can never contribute to a sealed quorum,
/// so {sealableMemberCount} counts this rather than counting role bits.
mapping(address account => bytes) private _activeSealKey;
/// @notice The live stage's ML-KEM-1024 encapsulation key, the lattice half of the pair.
/// @dev Two algorithms per stage — ML-KEM-1024 and HQC-5 — so a break in either family leaves the other
/// standing, the same reasoning that pairs the two signature families. The pair is written and
/// cleared together, so an account holds both or neither.
/// @dev Stored as the RAW keys, like the signing keys, because a registry that held only commitments
/// could not answer "encapsulate to this party" without a second lookup somewhere less
/// authoritative.
mapping(address account => bytes) private _activeKemMlKem;
/// @notice The live stage's HQC-5 encapsulation key, the code-based half of the pair.
mapping(address account => bytes) private _activeKemHqc;
/// @notice The recovery stage's ML-KEM-1024 encapsulation key. Empty when the account has no recovery
/// stage.
mapping(address account => bytes) private _recoveryKemMlKem;
/// @notice The recovery stage's HQC-5 encapsulation key. Empty when the account has no recovery stage.
mapping(address account => bytes) private _recoveryKemHqc;
/// @notice Reverse index. A certificate identifies exactly one account, so
/// presenting a `certHash` is enough to find who it belongs to.
mapping(bytes32 certHash => address account) public accountOfCertificate;
/// @notice Revocation by certificate, independent of the account record.
/// A certificate stays revoked even if its account is later re-registered
/// under a new one.
mapping(bytes32 certHash => bool) public certificateRevoked;
/// @notice Who revoked a certificate through the ISSUER half of the lane.
/// Scoped by the verifier: the entry binds only when the recorded revoker
/// is the certificate's own issuer. Never gates registration.
mapping(bytes32 certHash => address) public certificateRevokedBy;
/// @notice Every registered account, in registration order. Small by
/// construction — this is services and co-signers, not wallets.
address[] private _accounts;
/// @notice Bootstrap authority. Zero once `sealBootstrap` has run.
address public bootstrapAdmin;
/// @notice Whether registration still accepts the bootstrap admin.
bool public bootstrapSealed;
/// @notice Where identity mutations project the tree-8 leaf, same-tx.
/// Zero only before {wireStatePlane} — the deploy tooling wires it before
/// the first registration, and the projection is skipped while unset so
/// the wiring transaction itself can be ordered freely in the bootstrap
/// window.
address public stateTrees;
/// @notice Where the PERMANENT standing losses — revocation and LMS-key
/// supersession — are recorded, same-tx. Zero only before {wireStatePlane}.
address public revocationLog;
/// @notice Sealed `ROLE_REGISTRAR` approvals a membership mutation needs.
/// @dev Zero until set, and bootstrap cannot be sealed while it is zero or
/// unreachable: a registry sealed behind a threshold nobody can meet is a
/// registry nobody can ever write to again.
uint256 public registrarThreshold;
/// @notice Replay counter per verifying contract — this registry for its
/// own mutations, each state-plane contract for its configuration. Bound
/// into every registrar digest, so an approval is for exactly one action.
mapping(address caller => uint64) private _gateNonce;
/// @notice The identity a Final Chain sender belongs to. See the contract
/// notes: a sender is derived from the `activeTransaction` key and is not
/// the account.
mapping(address sender => address account) public accountOfSender;
// -------------------------------------------------------------- events
/// @notice An identity was registered, or an existing one rotated onto a new certificate set.
/// @param account The identity written.
/// @param certHash The live certificate's handle.
/// @param roles The capability bitmask now in force.
/// @param version The record's monotonic version.
event IdentityRegistered(
address indexed account, bytes32 indexed certHash, uint256 roles, uint64 version
);
/// @notice An identity's capability bitmask was replaced.
/// @param account The identity whose roles changed.
/// @param previousRoles The mask before the change.
/// @param newRoles The mask now in force.
event IdentityRolesChanged(address indexed account, uint256 previousRoles, uint256 newRoles);
/// @notice An account's hash-based signing key for one chain was recorded or rotated.
/// @param account The identity that holds the key.
/// @param signerId The fingerprint an execution chain's roster names.
/// @param chainId The chain the key is armed for.
/// @param keyId The LMS key identifier.
/// @param height The Merkle tree height.
/// @param root The LMS public key.
/// @param version The lineage counter for this account and chain.
event LmsKeyRegistered(
address indexed account,
bytes32 indexed signerId,
uint64 indexed chainId,
bytes16 keyId,
uint8 height,
bytes32 root,
uint64 version
);
/// @notice An identity was retired. Irreversible, and its roles are cleared in the same transaction.
/// @param account The identity that was revoked.
/// @param certHash The certificate it held at the time.
event IdentityRevoked(address indexed account, bytes32 indexed certHash);
/// @notice One revocation-lane entry.
/// @param certHash The certificate that was revoked.
/// @param revoker Zero for a root-plane revocation, the issuing identity for an issuer's own.
event CertificateRevoked(bytes32 indexed certHash, address indexed revoker);
/// @notice The bootstrap window closed. After this there is no single-caller write path left.
/// @param sealedBy The bootstrap admin that closed it, immediately before being cleared.
event BootstrapSealed(address indexed sealedBy);
/// @notice The one-shot state-plane wiring landed. Emitted at most once in this contract's lifetime.
/// @param stateTrees The state-trees contract that owns the identity tree.
/// @param revocationLog The append-only log of retired signer fingerprints.
event StatePlaneWired(address stateTrees, address revocationLog);
/// @notice The number of sealed registrar approvals a membership mutation needs was set.
/// @param threshold The new threshold.
event RegistrarThresholdSet(uint256 threshold);
/// @notice A registrar quorum authorized an action.
/// @param verifyingContract The contract the approvals were collected for, and whose counter was burned.
/// @param actionDomain The action domain the approvals bound.
/// @param nonce The counter value the approvals were made over; the next action needs the next one.
/// @param valid How many approvals verified.
event RegistrarQuorumApproved(
address indexed verifyingContract, bytes32 indexed actionDomain, uint64 nonce, uint256 valid
);
// -------------------------------------------------------------- errors
/// @notice The caller holds none of the authority the entry point requires.
/// @param caller The address that called.
error NotAuthorized(address caller);
/// @notice The bootstrap window is already closed. Closing it is irreversible.
error BootstrapAlreadySealed();
/// @notice No record claims this account, or a zero address was offered as one.
/// @param account The address that was named.
error UnknownAccount(address account);
/// @notice A certificate's encapsulation key failed the chain's own well-formedness check.
/// @dev Names the algorithm, because the pair is stored together and "one of these two" is not an
/// actionable answer.
/// @param account The account being registered.
/// @param algorithmId The algorithm whose key was malformed.
error MalformedEncapsulationKey(address account, uint16 algorithmId);
/// @notice The certificate is already bound to a different account. One certificate identifies exactly
/// one party.
/// @param certHash The certificate's handle.
/// @param boundTo The account that already holds it.
error CertificateAlreadyBound(bytes32 certHash, address boundTo);
/// @notice The certificate has been revoked, or the account's own certificate has. Revocation is never
/// undone, so this is terminal for that handle.
/// @param certHash The revoked certificate's handle.
error CertificateIsRevoked(bytes32 certHash);
/// @notice A registration or rotation did not advance the record's version. Monotonicity is what stops a
/// replayed transaction reinstating credentials their holder has moved off.
/// @param current The version on record.
/// @param offered The version the caller presented.
error VersionNotNewer(uint64 current, uint64 offered);
/// @notice The named account does not carry `ROLE_CERTIFICATE_AUTHORITY`, or does not currently stand.
/// @param issuer The account that was named.
error IssuerNotACertificateAuthority(address issuer);
/// @notice The named parent has reached its own delegation bound and may issue nothing further.
/// @param issuer The parent account.
/// @param depth The parent's depth.
/// @param maxDelegationDepth The deepest level the parent may issue to.
error IssuerMayNotSign(address issuer, uint8 depth, uint8 maxDelegationDepth);
/// @notice A certificate sits at a depth its lineage does not put it at. Levels cannot be skipped,
/// because skipping one is how an issuer escapes its own delegation bound.
/// @param got The depth the certificate declares.
/// @param want The depth its lineage requires.
error WrongDepth(uint8 got, uint8 want);
/// @notice A child certificate claims a deeper delegation bound than the parent that admits it.
/// @param child The child's `maxDelegationDepth`.
/// @param issuer The parent's `maxDelegationDepth`.
error DelegationWidened(uint8 child, uint8 issuer);
/// @notice The certificate names an authority key that is not its declared parent's subject key.
/// @param got The authority key identifier the certificate carries.
/// @param want The parent's subject key identifier.
error AuthorityKeyIdMismatch(bytes32 got, bytes32 want);
/// @notice The live and recovery certificates carry different serials, so they describe two different
/// certificate sets rather than two stages of one.
/// @param liveSerial The live certificate's serial.
/// @param recoverySerial The recovery certificate's serial.
error StagesDisagree(bytes32 liveSerial, bytes32 recoverySerial);
/// @notice An LMS tree height outside 1 through 24, the range the verifier admits.
/// @param height The height offered.
error LmsHeightOutOfRange(uint8 height);
/// @notice A zero LMS root commits to no tree and is refused.
error LmsRootIsZero();
/// @notice This signer fingerprint already belongs to a different account.
/// @param signerId The fingerprint offered.
/// @param boundTo The account that already holds it.
error LmsKeyAlreadyBound(bytes32 signerId, address boundTo);
/// @notice Two identities cannot share a transaction key: the sender it derives would be attributable to
/// both.
/// @param sender The derived sender address.
/// @param boundTo The account that already claims it.
error SenderAlreadyBound(address sender, address boundTo);
/// @notice Fewer registrars able to seal than the threshold asks for.
/// @param sealable How many standing registrars hold a seal key.
/// @param threshold How many approvals a membership mutation needs.
error RegistrarThresholdUnreachable(uint256 sealable, uint256 threshold);
/// @notice A zero registrar threshold was offered, or a quorum was demanded before one was set. A zero
/// threshold is a registry with no authority behind its membership.
error RegistrarThresholdIsZero();
/// @notice {wireStatePlane} has already run. Both pointers are trust topology and are written once.
error StatePlaneAlreadyWired();
/// @notice {wireStatePlane} was handed a zero address for the trees or for the revocation log.
error ZeroStatePlane();
/// @notice The holder's proof of possession did not verify: one family failed, or the digest was built
/// over the wrong nonce.
/// @param account The account the admission was for.
error AdmissionProofInvalid(address account);
/// @notice The certificate does not name the chain's authority key, so it is not chain-attested.
/// @param authorityKeyId The authority key identifier that was presented.
error NotChainAttested(bytes32 authorityKeyId);
/// @notice The certificate's issuer name is not the chain's own.
/// @param issuerDnHash The digest of the name that was presented.
error WrongIssuerDn(bytes32 issuerDnHash);
/// @notice A chain-attested end entity sits at depth 1 with `maxDelegationDepth == depth`; anything else
/// is not an end entity.
/// @param depth The certificate's position on the delegation axis.
/// @param maxDelegationDepth The deepest level it may issue to.
error NotAnEndEntity(uint8 depth, uint8 maxDelegationDepth);
/// @notice An issuer that cannot sign is an end entity wearing an issuer profile, and belongs in
/// {registerWallet}.
/// @param depth The certificate's position on the delegation axis.
/// @param maxDelegationDepth The deepest level it may issue to.
error IssuerCannotSign(uint8 depth, uint8 maxDelegationDepth);
/// @notice A registered issuer's certificate never expires.
/// @dev Expiry is the passive half of an issuer's lifecycle, so a zero `NotAfter` is refused here even
/// though the certificate schema allows one for an end entity.
error IssuerMustExpire();
/// @notice An issuer validity window past {MAX_ISSUER_VALIDITY_MS}.
/// @param notBefore The certificate's start, in this chain's milliseconds.
/// @param notAfter The certificate's end, in this chain's milliseconds.
error IssuerValidityTooLong(uint64 notBefore, uint64 notAfter);
/// @notice An institution registration whose subject name carries no ISO 3166 country component, or
/// whose institution extension is too short to hold one.
/// @dev Only the trust root is jurisdiction-silent; a registered institution names where it answers for
/// itself.
error JurisdictionMissing();
/// @notice The subject name's country and the institution extension's `jurisdiction` field disagree, or
/// the extension's jurisdiction is not a two-byte country code.
error JurisdictionMismatch();
// --------------------------------------------------------- constructor
/**
* @notice Deploy the registry with a bootstrap registrar in place.
* @dev The precompile probe is the point of the constructor. This contract is meaningless on a chain
* that cannot verify post-quantum signatures, and deploying it there would produce a registry full
* of keys nothing on that chain can check — so it refuses to exist where the precompiles are
* absent rather than existing and being trusted.
*
* The admin is the whole authority until {sealBootstrap} runs, because every roster has to be
* installed by someone before it can install itself.
* @param admin The bootstrap registrar. Genesis names the chain deployer.
*/
constructor(address admin) {
FinalChainPrecompiles.assertAvailable();
bootstrapAdmin = admin;
}
// ----------------------------------------------------------- authority
/**
* @notice The authority gate on every membership mutation this registry performs.
* @dev Bootstrap is a real window, not a formality: every roster in this system has to be installed by
* someone before it can install itself, and a design that pretends otherwise ends up with a roster
* that cannot be brought into existence at all. It is closed by {sealBootstrap}, irreversibly.
*
* While the window is open the admin writes alone. Once it is closed there is no single-caller path
* left — not for a registrar, not for anyone — and every mutation goes through the sealed registrar
* quorum, whose approvals carry both signature families.
* @param actionDomain One of the `DOMAIN_*` constants naming the mutation.
* @param payloadDigest The mutation's own arguments, folded.
* @param anchorBlock The block the registrars read the roster at. Ignored while bootstrap is open.
* @param approvals The sealed registrar quorum. Empty while bootstrap is open.
*/
function _requireMembershipAuthority(
bytes32 actionDomain,
bytes32 payloadDigest,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) private {
if (!bootstrapSealed && msg.sender == bootstrapAdmin) return;
_requireRegistrarQuorum(address(this), actionDomain, payloadDigest, anchorBlock, approvals);
}
/**
* @notice The sealed registrar quorum, for the other contracts in the state plane.
* @dev `msg.sender` — the calling contract — is the verifying contract the digest binds and the counter
* it burns, so an approval collected for one contract's configuration cannot be spent on another's.
* The caller decides its own bootstrap exemption before calling; this function knows no caller's
* admin and applies none.
*
* Anyone may SUBMIT such a transaction. Authority is the approvals, not the sender, which is the
* whole point of a quorum.
* @param actionDomain The caller's own action domain for the change being authorised.
* @param payloadDigest The change's arguments, folded by the caller.
* @param anchorBlock The block the registrars read the roster at.
* @param approvals The registrar approvals, each carrying both families.
*/
function requireRegistrarQuorum(
bytes32 actionDomain,
bytes32 payloadDigest,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireRegistrarQuorum(msg.sender, actionDomain, payloadDigest, anchorBlock, approvals);
}
/// @notice Burn one gate nonce and require a sealed registrar quorum over the action.
/// @dev The digest is `FinalPqQuorum.digest(verifyingContract, actionDomain, anchorBlock,
/// keccak256(abi.encode(nonce, payloadDigest)))`. The counter is burned BEFORE verification, so an
/// approval set is spent whether or not it turns out to be sufficient.
///
/// The seal is required rather than optional: membership is the hybrid class, and an approval
/// carrying only the lattice vote is not an approval here.
/// @param verifyingContract The contract the approvals are for, and whose counter is burned.
/// @param actionDomain One of the `DOMAIN_*` constants, so an approval to grant cannot be replayed to
/// revoke.
/// @param payloadDigest The action's own arguments, folded.
/// @param anchorBlock The block the registrars read the roster at.
/// @param approvals The registrar approvals, each carrying both families.
function _requireRegistrarQuorum(
address verifyingContract,
bytes32 actionDomain,
bytes32 payloadDigest,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) private {
if (registrarThreshold == 0) revert RegistrarThresholdIsZero();
uint64 nonce = _gateNonce[verifyingContract];
_gateNonce[verifyingContract] = nonce + 1;
bytes32 quorumDigest = FinalPqQuorum.digest(
verifyingContract, actionDomain, anchorBlock, keccak256(abi.encode(nonce, payloadDigest))
);
uint256 valid = FinalPqQuorum.require_(
this,
approvals,
quorumDigest,
ROLE_REGISTRAR,
registrarThreshold,
FinalPqQuorum.ALG_ML_DSA_87,
anchorBlock,
true
);
emit RegistrarQuorumApproved(verifyingContract, actionDomain, nonce, valid);
}
/**
* @notice Set how many sealed registrar approvals a membership mutation needs.
* @dev The bootstrap admin while the window is open; the current registrar quorum afterwards, so a
* registrar set that grows or shrinks can move the threshold to match itself.
*
* Refuses a threshold the sealable registrars cannot meet, and refuses zero. Both are a registry
* that can never be written to again, and the way that presents is every membership mutation
* reverting forever with nothing naming the threshold as the cause.
* @param threshold How many sealed approvals a mutation needs. Must be reachable and non-zero.
* @param anchorBlock The block the registrars read the roster at. Ignored while bootstrap is open.
* @param approvals The sealed registrar quorum. Empty while bootstrap is open.
*/
function setRegistrarThreshold(
uint256 threshold,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireMembershipAuthority(
DOMAIN_SET_REGISTRAR_THRESHOLD, keccak256(abi.encode(threshold)), anchorBlock, approvals
);
if (threshold == 0) revert RegistrarThresholdIsZero();
uint256 sealable = sealableMemberCount(ROLE_REGISTRAR);
if (sealable < threshold) revert RegistrarThresholdUnreachable(sealable, threshold);
registrarThreshold = threshold;
emit RegistrarThresholdSet(threshold);
}
/// @notice The replay counter the next registrar approval for `caller` must be made over.
/// @dev One counter per verifying contract, so an approval collected for one contract's configuration
/// cannot be spent on another's. A caller reads this to build the digest its registrars will sign.
/// @param caller The verifying contract the approvals will name — this registry for its own mutations.
/// @return The value the next approval must bind.
function gateNonceOf(address caller) external view returns (uint64) {
return _gateNonce[caller];
}
// -------------------------------------------------------- LMS signers
/**
* @notice The roster identity of an LMS public key.
* @dev Byte-identical to `FinalRootAuthority.signerId` on the execution chains. Restated rather than
* imported because the two live on different chains and no import would make them one value —
* which is precisely why a test pins them together. A drift here would make every lookup miss while
* looking perfectly well-formed.
*
* The height is bound into the fingerprint as well as the root, because a leaf commits to a node
* number derived from it, so a signer free to vary the height could vary the numbering.
* @param keyId The LMS key identifier.
* @param height The Merkle tree height.
* @param root The LMS public key.
* @return The fingerprint an execution chain's roster names.
*/
function lmsSignerId(bytes16 keyId, uint8 height, bytes32 root) public pure returns (bytes32) {
return keccak256(abi.encode(keyId, height, root));
}
/**
* @notice Record the hash-based (LMS) signing key an already-registered account holds for one chain.
* @dev Membership-gated, like every other write here.
*
* Deliberately NOT a certificate: an LMS key is a capability of an existing identity, not an
* identity of its own. Binding it to an account means it inherits that account's revocation, so
* retiring a compromised operator is one action rather than one action per key they hold.
*
* A rotation records the SUPERSEDED fingerprint into the revocation log in the same transaction, so
* the execution chains' suspension lane never depends on someone noticing. The superseded
* fingerprint is left BOUND to this account rather than cleared, because attribution is history.
*
* A zero `chainId` is a tooling mistake rather than an attack — the slot it occupies is
* self-consistent and no authority consults it — so the publisher refuses it off chain and this
* contract spends no bytecode on the check.
* @param account Must already be registered and not revoked.
* @param chainId The execution chain this key is armed for.
* @param keyId The LMS key identifier, hashed into every step of a signature under it.
* @param height The Merkle tree height, 1 through 24.
* @param root The LMS public key. Zero commits to no tree and is refused.
* @param version Strictly increasing per account and chain. A rotation that does not advance it is
* refused, so a replayed registration cannot reinstate a key the operator has moved off.
* @param anchorBlock The block the registrars read the roster at. Ignored while bootstrap is open.
* @param approvals The sealed registrar quorum. Empty while bootstrap is open.
*/
function registerLmsKey(
address account,
uint64 chainId,
bytes16 keyId,
uint8 height,
bytes32 root,
uint64 version,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireMembershipAuthority(
DOMAIN_REGISTER_LMS_KEY,
keccak256(abi.encode(account, chainId, keyId, height, root, version)),
anchorBlock,
approvals
);
Identity storage id = _identity[account];
if (!id.registered) revert UnknownAccount(account);
if (id.revoked) revert CertificateIsRevoked(id.certHash);
// A zero chain id is a tooling mistake, not an attack: the slot it
// would occupy is self-consistent and no authority consults it. The
// publisher refuses it; EIP-170 pressure keeps the check off-chain.
if (height == 0 || height > 24) revert LmsHeightOutOfRange(height);
if (root == bytes32(0)) revert LmsRootIsZero();
// Version lineage is PER account and chain: the same operator is a different signer on every chain,
// so one chain starting at version 1 says nothing about another already being at version 3.
LmsKey storage existing = _lmsKey[account][chainId];
// An empty slot holds version 0, so this alone also refuses a version-0
// registration — versions start at 1.
if (version <= existing.version) {
revert VersionNotNewer(existing.version, version);
}
bytes32 signerId = lmsSignerId(keyId, height, root);
address boundTo = _lmsBinding[signerId].account;
if (boundTo != address(0) && boundTo != account) {
revert LmsKeyAlreadyBound(signerId, boundTo);
}
// The fingerprint being superseded, captured before the slot moves —
// `existing` is a storage pointer and reads the NEW key afterwards.
bytes32 superseded = existing.registered
? lmsSignerId(existing.keyId, existing.height, existing.root)
: bytes32(0);
// The superseded fingerprint is left bound to this account rather than
// cleared. It is history: a signature made under the old key was made
// by this operator, and a lookup that stopped resolving would make that
// unprovable after the fact.
_lmsKey[account][chainId] = LmsKey(keyId, height, root, version, true);
_lmsBinding[signerId] = LmsBinding(account, chainId);
emit LmsKeyRegistered(account, signerId, chainId, keyId, height, root, version);
// Supersession is a PERMANENT transition — the old fingerprint stops
// being this slot's current key and nothing re-registers it (a
// re-registration of the same material is the same fingerprint, which
// the guard below leaves alone). Recorded same-tx so the execution
// chains' suspension lane never depends on someone noticing.
if (superseded != bytes32(0) && superseded != signerId) {
_recordRevokedSigner(superseded);
}
_projectIdentity(account);
}
/// @notice The LMS key an account holds for one chain, if any.
/// @dev Keyed per account AND per chain, because a single-use hash-based counter is only complete while
/// the key it names signs for one chain. `registered` is the field to branch on; the zero struct
/// means no key rather than a key of zeroes.
/// @param account The identity to read.
/// @param chainId The chain the key is armed for.
/// @return The stored key, copied to memory.
function lmsKeyOf(address account, uint64 chainId) external view returns (LmsKey memory) {
return _lmsKey[account][chainId];
}
/// @notice What a fingerprint is bound to: the account that registered it and the chain it signs for.
/// @dev The binding survives supersession, because attribution is history: a signature made under a
/// retired key was still made by that operator, and a lookup that stopped resolving would make that
/// unprovable after the fact. Standing is a separate question, answered by {lmsSignerIsLive}.
///
/// The revocation log's permanence gate reads this to find the slot a fingerprint belongs to; that
/// slot's current key is what separates a superseded fingerprint, which is permanent and
/// recordable, from a merely lapsed one, which renewal undoes.
/// @param signerId The fingerprint to resolve.
/// @return account The account that registered it, or zero for a fingerprint never registered.
/// @return chainId The chain that registration was for, or zero alongside a zero account.
function lmsBindingOf(bytes32 signerId) external view returns (address account, uint64 chainId) {
LmsBinding storage binding = _lmsBinding[signerId];
return (binding.account, binding.chainId);
}
/**
* @notice Whether a signer fingerprint is held by a standing, unrevoked account.
* @dev The question a verifier actually has. An execution chain's authority roster names fingerprints
* and learns nothing else about them, so without this the keys behind those names are
* unanswerable from the state plane.
*
* Standing is asked through {isActive} rather than by spelling the conditions out again, because a
* second spelling is how two answers drift: an expired identity already holds no role, and a signer
* lookup that disagreed would leave a roster satisfiable by an operator the rest of the registry
* has stopped honouring.
*
* Live means the CURRENT key of the fingerprint's own account-and-chain slot, not merely one this
* account ever held. A superseded fingerprint stays attributable but stops being live, and a
* rotation on one chain says nothing about the same operator's key on another.
* @param signerId The fingerprint an authority roster names.
* @return live Whether the fingerprint is that slot's current key and the account still stands.
* @return account The account the fingerprint is bound to, or zero when none ever registered it.
*/
function lmsSignerIsLive(bytes32 signerId) external view returns (bool live, address account) {
LmsBinding storage binding = _lmsBinding[signerId];
account = binding.account;
if (account == address(0)) return (false, address(0));
// `isActive`, not a registered/revoked pair spelled out here. The
// certificate validity window is part of standing: an expired identity
// already holds no role, and a signer lookup that disagreed would leave
// a roster satisfiable by an operator the rest of the registry has
// stopped honouring. Spelling the condition out a second time is how
// the two drift apart.
if (!isActive(account)) return (false, account);
// The CURRENT key of the fingerprint's own (account, chain) slot, not
// merely one this account ever held: a superseded fingerprint stays
// attributable but stops being live, and a rotation on one chain says
// nothing about the same operator's key on another.
LmsKey storage k = _lmsKey[account][binding.chainId];
live = k.registered && lmsSignerId(k.keyId, k.height, k.root) == signerId;
}
/// @notice Close the bootstrap window. Irreversible.
/// @dev Refuses while the registrar quorum is unset or unreachable, because sealing then would leave a
/// registry nobody can ever write to again — including to fix the threshold that locked it. The
/// count is of registrars that can SEAL: a certificate authority carrying the registrar role is
/// registered from a certificate with no seal slot and can never contribute an approval, so
/// counting role bits alone would seal onto a quorum that looks reachable and is not.
///
/// Clears the admin as well as setting the flag, so no single-caller path survives the seal.
function sealBootstrap() external {
if (msg.sender != bootstrapAdmin) revert NotAuthorized(msg.sender);
if (bootstrapSealed) revert BootstrapAlreadySealed();
if (registrarThreshold == 0) revert RegistrarThresholdIsZero();
uint256 sealable = sealableMemberCount(ROLE_REGISTRAR);
if (sealable < registrarThreshold) {
revert RegistrarThresholdUnreachable(sealable, registrarThreshold);
}
bootstrapSealed = true;
bootstrapAdmin = address(0);
emit BootstrapSealed(msg.sender);
}
// ------------------------------------------------- state-plane wiring
/**
* @notice Wire the state trees and the revocation log, once, inside the bootstrap window.
* @dev One-shot because both pointers are TRUST TOPOLOGY: the trees pointer decides where the
* wallet-creation admission set is written, and the log pointer decides where permanent standing
* losses are recorded. A re-wireable pointer would be a key over both.
*
* It cannot be a constructor argument, because both of those contracts take THIS registry as one of
* theirs. The deploy tooling calls it in the same nonce-fixed block that deploys them, before any
* identity is registered, which is why the projection is silently skipped while the pointers are
* zero rather than reverting.
* @param stateTrees_ The state-trees contract that owns tree 8. Zero is refused.
* @param revocationLog_ The append-only log of retired signer fingerprints. Zero is refused.
*/
function wireStatePlane(address stateTrees_, address revocationLog_) external {
if (bootstrapSealed || msg.sender != bootstrapAdmin) revert NotAuthorized(msg.sender);
if (stateTrees != address(0) || revocationLog != address(0)) revert StatePlaneAlreadyWired();
if (stateTrees_ == address(0) || revocationLog_ == address(0)) revert ZeroStatePlane();
stateTrees = stateTrees_;
revocationLog = revocationLog_;
emit StatePlaneWired(stateTrees_, revocationLog_);
}
/// @notice Refresh `account`'s tree-8 leaf in the state trees, same transaction.
/// @dev Skipped while the plane is unwired, which is a bootstrap-window state the deploy tooling closes
/// before the first registration, and never otherwise. The leaf VALUE is derived by the trees
/// contract from this registry's post-mutation state, so there is nothing here to get wrong beyond
/// forgetting to call it — which is why every mutation calls it, including the one that cannot
/// change the leaf.
/// @param account The identity whose leaf is stale.
function _projectIdentity(address account) private {
address trees = stateTrees;
if (trees == address(0)) return;
address[] memory one = new address[](1);
one[0] = account;
IIdentityLeafSink(trees).syncIdentityLeaves(one);
}
/// @notice Record a permanently retired signer fingerprint into the revocation log, same transaction.
/// @dev Skipped while the log is unwired, and skipped when somebody already recorded the fingerprint
/// through the log's permissionless door — the log refuses a duplicate, and a membership mutation
/// must not be revertible by a stranger who front-ran its bookkeeping.
/// @param signerId The fingerprint that has lost standing for good.
function _recordRevokedSigner(bytes32 signerId) private {
address log = revocationLog;
if (log == address(0)) return;
if (IRevocationRecorder(log).recorded(signerId)) return;
IRevocationRecorder(log).record(signerId);
}
// -------------------------------------------------------- registration
/**
* @title Admission Proof
* @notice The holder's proof of possession at admission: both live-stage families over the admission
* digest.
* @dev There is no root keypair and no issuer signature on this path. The chain admits, and the two
* signatures presented at creation are the HOLDER's, verified by the precompiles inside the same
* transaction that writes the record. Possession lives in the TRANSACTION, never in the artifact:
* a public certificate is a document anyone may hold, so presenting one proves nothing.
*/
struct AdmissionProof {
/// The holder's ML-DSA-87 signature under the live TRANSACTION key, over the admission digest.
bytes mlDsaSignature;
/// The holder's SLH-DSA-SHAKE-256s signature under the live ACCESS key, over the same digest. Two
/// families over one message, so neither a lattice break nor a hash-function break alone admits an
/// identity.
bytes slhDsaSignature;
}
/**
* @notice Register or rotate a Final Wallet identity from its two public certificates.
* @dev **Both stages, together.** A wallet has four keys in two stages and the recovery pair is
* PRE-COMMITTED — written at wallet initialization from the same certificate set that determined
* the wallet's address, which is why enabling post-quantum mode later takes no key arguments. The
* two certificates must share a serial: a serial is per certificate SET, so two stages that
* disagree about it are two different wallets.
*
* **Chain-attested means pinned, per stage:** the chain's issuer name and authority key, depth
* exactly 1 so the certificate hangs directly under the chain, and `maxDelegationDepth == depth` so
* the holder issues nothing. That immutable pair is what {identityTreeLeafOf} discriminates record
* kinds by.
*
* Issuance authority is the registrar quorum and possession is the holder's own proof; there is no
* root keypair anywhere and no certificate-authority signature over this admission.
* @param account The wallet address the certificate set derives.
* @param liveTbs The live certificate's TBS bytes: the live transaction and access keys.
* @param recoveryTbs The recovery certificate's TBS bytes: the pre-committed recovery pair.
* @param proof The holder's two signatures over the admission digest — the live transaction key
* (ML-DSA-87) and the live access key (SLH-DSA-SHAKE-256s), both verified in the precompiles
* inside this transaction.
* @param roles Capability bitmask. The one thing the certificates do not say, because capability is this
* system's decision rather than the certificate's.
* @param version Monotonic. A rotation that does not advance it is refused.
* @param anchorBlock The block the registrars read the roster at. Ignored while bootstrap is open.
* @param approvals The sealed registrar quorum. Empty while bootstrap is open. The digest binds the
* account, both certificates' bytes, the roles and the version.
* @return certHash The handle the live certificate is now known by.
*/
function registerWallet(
address account,
bytes calldata liveTbs,
bytes calldata recoveryTbs,
AdmissionProof calldata proof,
uint256 roles,
uint64 version,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external returns (bytes32 certHash) {
// Read BEFORE the authority check: the quorum path burns this counter
// inside `_requireRegistrarQuorum`, and the proof must bind the value
// the round was built over. The bootstrap path burns it explicitly in
// `_requireAdmissionProof`, so an admission is one-shot in both regimes.
uint64 admissionNonce = _gateNonce[address(this)];
_requireMembershipAuthority(
DOMAIN_REGISTER_WALLET,
keccak256(
abi.encode(account, keccak256(liveTbs), keccak256(recoveryTbs), roles, version)
),
anchorBlock,
approvals
);
FinalCertificate.Parsed memory l = FinalCertificate.parseLive(liveTbs);
FinalCertificate.Parsed memory r = FinalCertificate.parseRecovery(recoveryTbs);
if (l.serial != r.serial) revert StagesDisagree(l.serial, r.serial);
_requireChainAttestedEndEntity(l);
_requireChainAttestedEndEntity(r);
_requireAdmissionProof(account, l, r.certHash, proof, admissionNonce);
certHash = l.certHash;
_write(account, l, r, roles, version, false);
}
/**
* @notice Register or rotate an ISSUER: a third party, or one of this system's own intermediates, that
* signs certificates off chain with the keys registered here.
* @dev Admission is chain-native like any identity — the registrar quorum authorises, and the holder's
* own proof of possession establishes that the party controls the keys it is claiming. The
* delegation rules survive as LINEAGE: a nested issuer's depth, delegation bound and
* `AuthorityKeyId` must chain to its registered parent. No parent signs anything; this chain's
* admission IS the issuance.
*
* A registered issuer always expires, and its window is bounded by {MAX_ISSUER_VALIDITY_MS}.
*
* An institution must carry its real ISO 3166 country in its subject name, matching the
* `jurisdiction` field of its institution extension. That is enforced at the door because a
* verifier's legal recourse starts with knowing where an issuer answers for itself.
*
* `ROLE_CERTIFICATE_AUTHORITY` is added to whatever `roles` asks for, rather than being required in
* it: the capability is what this entry point means, so it cannot be forgotten in an argument.
* @param account The issuer's account on this chain.
* @param tbs The issuer certificate's TBS bytes: two cert-signing keys, ML-DSA-87 and
* SLH-DSA-SHAKE-256s, and no recovery stage — renewing an issuer is re-issuing, a governance act
* rather than a key rotation.
* @param parent The registered parent issuer for a nested intermediate; zero for an issuer hanging
* directly under the chain.
* @param proof The issuer's own two cert-signing keys over the admission digest. The recovery-handle
* slot in that digest is zero, because there is no recovery stage to bind.
* @param roles Capability bitmask, over and above the certificate-authority bit this call adds.
* @param version Monotonic. A rotation that does not advance it is refused.
* @param anchorBlock The block the registrars read the roster at. Ignored while bootstrap is open.
* @param approvals The sealed registrar quorum. Empty while bootstrap is open. The digest binds the
* account, the certificate bytes, the parent, the roles and the version.
* @return certHash The handle the registered certificate is now known by.
*/
function registerIssuer(
address account,
bytes calldata tbs,
address parent,
AdmissionProof calldata proof,
uint256 roles,
uint64 version,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external returns (bytes32 certHash) {
uint64 admissionNonce = _gateNonce[address(this)];
_requireMembershipAuthority(
DOMAIN_REGISTER_ISSUER,
keccak256(abi.encode(account, keccak256(tbs), parent, roles, version)),
anchorBlock,
approvals
);
FinalCertificate.Parsed memory c = FinalCertificate.parseCa(tbs);
// An issuer that cannot sign is an end entity wearing a profile —
// and an end entity belongs in `registerWallet`.
if (c.depth == 0 || c.maxDelegationDepth <= c.depth) {
revert IssuerCannotSign(c.depth, c.maxDelegationDepth);
}
if (c.notAfter == 0) revert IssuerMustExpire();
if (c.notAfter - c.notBefore > MAX_ISSUER_VALIDITY_MS) {
revert IssuerValidityTooLong(c.notBefore, c.notAfter);
}
if (c.issuerDnHash != CHAIN_ISSUER_DN_HASH) revert WrongIssuerDn(c.issuerDnHash);
_requireLineage(parent, c);
_requireJurisdiction(c);
_requireAdmissionProof(account, c, bytes32(0), proof, admissionNonce);
certHash = c.certHash;
_write(account, c, c, roles | ROLE_CERTIFICATE_AUTHORITY, version, true);
}
/// @notice The validity ceiling a registered issuer's certificate may not exceed, in this chain's
/// milliseconds: two 366-day years.
/// @dev Expiry is the passive half of an issuer's lifecycle — the touchpoint that proves an issuer is
/// still there without anyone having to act — so a registered issuer always carries a real
/// `NotAfter` and a bounded window. Renewal re-issues under the same registered keys with a version
/// bump rather than extending a certificate in place.
uint64 public constant MAX_ISSUER_VALIDITY_MS = 2 * 366 days * 1000;
/// @notice Pin one stage of a chain-attested end-entity certificate.
/// @dev Three checks, run once per stage: the certificate names the chain's authority key, it carries the
/// chain's issuer name, and its depth pair is exactly that of an end entity — depth 1, directly
/// under the chain, issuing nothing. The depth pair is immutable per version, which is why
/// {identityTreeLeafOf} discriminates record kinds by it rather than by a role bit.
/// @param c The parsed certificate stage.
function _requireChainAttestedEndEntity(FinalCertificate.Parsed memory c) private pure {
if (c.authorityKeyId != CHAIN_AUTHORITY_KEY_ID) revert NotChainAttested(c.authorityKeyId);
if (c.issuerDnHash != CHAIN_ISSUER_DN_HASH) revert WrongIssuerDn(c.issuerDnHash);
if (c.depth != 1 || c.maxDelegationDepth != c.depth) {
revert NotAnEndEntity(c.depth, c.maxDelegationDepth);
}
}
/// @notice Check a nested issuer's lineage to its registered parent.
/// @dev Delegation is governed by DEPTH, not by a boolean: a parent may sign only while
/// `depth < maxDelegationDepth`, a child sits exactly one level down so it cannot skip levels to
/// escape that bound, and its own bound may never widen past its parent's. The child's
/// `AuthorityKeyId` must equal the parent's `SubjectKeyId`, which is the link the chain follows.
///
/// A zero `parent` means the issuer hangs directly under the chain: it must then name the chain's
/// own authority key and sit at depth 1. No parent SIGNS anything here — admission by this chain is
/// the issuance, and lineage is what keeps the delegation bounds honest across it.
/// @param parent The registered parent issuer, or zero for one directly under the chain.
/// @param c The parsed issuer certificate.
function _requireLineage(address parent, FinalCertificate.Parsed memory c) private view {
if (parent == address(0)) {
if (c.authorityKeyId != CHAIN_AUTHORITY_KEY_ID) {
revert NotChainAttested(c.authorityKeyId);
}
if (c.depth != 1) revert WrongDepth(c.depth, 1);
return;
}
Identity storage ca = _identity[parent];
if (!hasRole(parent, ROLE_CERTIFICATE_AUTHORITY)) {
revert IssuerNotACertificateAuthority(parent);
}
// Delegation is governed by depth, not by a boolean. `Depth <
// MaxDelegationDepth` permits signing, and a child sits exactly one
// level down — an issuer cannot skip levels to escape its own bound.
if (ca.depth >= ca.maxDelegationDepth) {
revert IssuerMayNotSign(parent, ca.depth, ca.maxDelegationDepth);
}
if (c.depth != ca.depth + 1) revert WrongDepth(c.depth, ca.depth + 1);
if (c.maxDelegationDepth > ca.maxDelegationDepth) {
revert DelegationWidened(c.maxDelegationDepth, ca.maxDelegationDepth);
}
if (c.authorityKeyId != ca.subjectKeyId) {
revert AuthorityKeyIdMismatch(c.authorityKeyId, ca.subjectKeyId);
}
}
/// @notice Refuse an issuer whose subject name carries no jurisdiction, or one that disagrees with its
/// institution extension.
/// @dev An issuer that answers for itself somewhere is an issuer a verifier has recourse against, so a
/// registered institution must name its jurisdiction and must name it once. Only the trust root is
/// jurisdiction-silent, because the root is the worldwide network rather than a legal entity.
///
/// The rule is a real ISO 3166 alpha-2 `C=` component in the subject name, equal to the
/// `jurisdiction` field of the certificate's institution extension. The name is in canonical
/// comma-separated form, so `C=` matches at the start or immediately after a comma, and the
/// component value is exactly two bytes — a longer one is a different component that happens to
/// start with the same letter.
/// @param c The parsed issuer certificate.
function _requireJurisdiction(FinalCertificate.Parsed memory c) private pure {
bytes memory dn = c.subjectDn;
bytes2 country;
bool found = false;
for (uint256 i = 0; i + 4 <= dn.length; i++) {
if ((i == 0 || dn[i - 1] == ",") && dn[i] == "C" && dn[i + 1] == "=") {
// Exactly two bytes, then end-of-DN or the next component.
if (i + 4 < dn.length && dn[i + 4] != ",") revert JurisdictionMissing();
country = bytes2(bytes.concat(dn[i + 2], dn[i + 3]));
found = true;
break;
}
}
if (!found) revert JurisdictionMissing();
// Institution extension: legalNameLength ‖ legalName ‖
// registrationNoLength ‖ registrationNo ‖ jurisdictionLength ‖
// jurisdiction. The jurisdiction must EQUAL the DN's country.
bytes memory ext = c.institutionExt;
if (ext.length < 6) revert JurisdictionMissing();
uint256 q = 2 + (uint256(uint8(ext[0])) << 8 | uint256(uint8(ext[1])));
if (ext.length < q + 2) revert JurisdictionMissing();
q += 2 + (uint256(uint8(ext[q])) << 8 | uint256(uint8(ext[q + 1])));
if (ext.length < q + 2) revert JurisdictionMissing();
uint256 jLen = uint256(uint8(ext[q])) << 8 | uint256(uint8(ext[q + 1]));
q += 2;
if (jLen != 2 || ext.length < q + 2) revert JurisdictionMismatch();
if (bytes2(bytes.concat(ext[q], ext[q + 1])) != country) revert JurisdictionMismatch();
}
/// @notice Verify the holder's proof of possession over the admission digest.
/// @dev Both live-stage families, in the precompiles, inside this transaction: an ML-DSA-87 signature
/// under the certificate's transaction key and an SLH-DSA-SHAKE-256s signature under its access
/// key. Possession lives in the TRANSACTION rather than in the artifact, so holding a copy of
/// somebody's public certificate proves nothing.
///
/// The keys come out of the certificate being admitted, not out of calldata, which is what makes
/// this a proof rather than a self-signed assertion.
///
/// Burns the gate nonce on the bootstrap path — the quorum path burned it already — so an admission
/// is one-shot in both regimes and a captured proof cannot be replayed into a second registration.
/// @param account The account being admitted; named in the revert so a failure is attributable.
/// @param live The parsed live-stage certificate whose keys verify the proof.
/// @param recoveryCertHash The recovery certificate's handle, bound into the digest; zero for an issuer.
/// @param proof The holder's two signatures.
/// @param admissionNonce The gate-nonce value the digest was built over.
function _requireAdmissionProof(
address account,
FinalCertificate.Parsed memory live,
bytes32 recoveryCertHash,
AdmissionProof calldata proof,
uint64 admissionNonce
) private {
bytes memory message = abi.encodePacked(
keccak256(
abi.encode(
DOMAIN_IDENTITY_ADMISSION,
block.chainid,
address(this),
live.certHash,
recoveryCertHash,
admissionNonce
)
)
);
if (
!FinalChainPrecompiles.verifyMlDsa87(live.transactionKey, message, proof.mlDsaSignature)
|| !FinalChainPrecompiles.verifySlhDsa(live.accessKey, message, proof.slhDsaSignature)
) revert AdmissionProofInvalid(account);
if (_gateNonce[address(this)] == admissionNonce) {
_gateNonce[address(this)] = admissionNonce + 1;
}
}
/**
* @notice Commit one parsed certificate set to storage and project the result.
* @dev The single write path behind both registration entry points, so a wallet record and an issuer
* record cannot diverge in how they are stored. Every authorization, parse and pin has already run;
* what is left is the ordering that keeps the record consistent with its indexes.
*
* A rotation RELEASES the previous certificate's binding rather than revoking it: a superseded
* certificate and a compromised one are different facts, and revocation is the louder of the two.
* The sender binding moves with the transaction key for the same reason — a rotation is the account
* disowning that key, and a gate that still resolved the old sender would honour a retired key.
*
* A certificate already bound to another account is refused, and so is a version that does not
* advance, so neither a replayed registration nor a stolen certificate can take a record over.
* @param account The identity being written. Zero is refused.
* @param live The parsed live-stage certificate; for an issuer, its single certificate.
* @param recovery The parsed recovery-stage certificate; for an issuer, the same value, discarded.
* @param roles The complete capability bitmask to store.
* @param version Monotonic per account. Must exceed the stored value.
* @param isCa Whether this is a certificate authority, which stores no recovery, seal or
* encapsulation material.
*/
function _write(
address account,
FinalCertificate.Parsed memory live,
FinalCertificate.Parsed memory recovery,
uint256 roles,
uint64 version,
bool isCa
) private {
if (account == address(0)) revert UnknownAccount(account);
if (certificateRevoked[live.certHash]) revert CertificateIsRevoked(live.certHash);
address boundTo = accountOfCertificate[live.certHash];
if (boundTo != address(0) && boundTo != account) {
revert CertificateAlreadyBound(live.certHash, boundTo);
}
Identity storage id = _identity[account];
if (!id.registered) {
_accounts.push(account);
id.registered = true;
} else {
if (version <= id.version) revert VersionNotNewer(id.version, version);
if (id.revoked) revert CertificateIsRevoked(id.certHash);
// A rotation releases the previous certificate's binding. It is NOT
// revoked — a superseded certificate and a compromised one are
// different facts and revocation is the louder of the two.
if (id.certHash != live.certHash) delete accountOfCertificate[id.certHash];
}
id.certHash = live.certHash;
id.recoveryCertHash = recovery.certHash;
id.serial = live.serial;
id.subjectKeyId = live.subjectKeyId;
id.roles = roles;
id.depth = live.depth;
id.maxDelegationDepth = live.maxDelegationDepth;
id.notBefore = live.notBefore;
id.notAfter = live.notAfter;
id.version = version;
// The sender binding moves with the transaction key. The old sender is
// released rather than kept: a rotation is the account disowning that
// key, and a gate that still resolved it would honour a retired key.
address sender = senderFor(live.transactionKey);
address senderBoundTo = accountOfSender[sender];
if (senderBoundTo != address(0) && senderBoundTo != account) {
revert SenderAlreadyBound(sender, senderBoundTo);
}
if (_activeTransactionKey[account].length != 0) {
address previousSender = senderFor(_activeTransactionKey[account]);
if (previousSender != sender) delete accountOfSender[previousSender];
}
accountOfSender[sender] = account;
_activeTransactionKey[account] = live.transactionKey;
_activeAccessKey[account] = live.accessKey;
// A CA has no recovery pair; the two active slots are all it has.
_recoveryTransactionKey[account] = isCa ? bytes("") : recovery.transactionKey;
_recoveryAccessKey[account] = isCa ? bytes("") : recovery.accessKey;
// Cleared on a rotation to a certificate without one, for the same
// reason the encapsulation pair is: a stale seal surviving a rotation
// would let a retired key keep co-signing execution.
_activeSealKey[account] = isCa ? bytes("") : live.sealKey;
// The encapsulation pair, validated before it is stored.
//
// **The registry is where a sender looks up "encapsulate to this
// party", so a malformed key here is not a bad record — it is an
// account nobody can seal an intent to.** The discovery would happen at
// the first attempt, and on the hybrid path it would happen as a pair
// silently reduced to one family, which is identical on the wire. The
// precompiles make it a refusal at registration instead.
//
// Neither is a re-implementation of the KEM: `0x0203` runs FIPS 203
// §7.2's own encapsulation-key check and `0x0207` runs the structural
// check HQC-5's encoding admits. Encapsulation is a sender operation
// and decapsulation needs the secret key, so nothing more belongs here.
//
// A CA is sealed to by nobody and carries no encapsulation stage, so
// its slots are cleared rather than checked.
_storeKemPair(account, isCa, live.kemMlKem, live.kemHqc, true);
_storeKemPair(account, isCa, recovery.kemMlKem, recovery.kemHqc, false);
accountOfCertificate[live.certHash] = account;
emit IdentityRegistered(account, live.certHash, roles, version);
// Same-tx: a registration or rotation is visible to every execution
// chain's admission set the moment it is visible here.
_projectIdentity(account);
}
/**
* @notice Store one stage's encapsulation pair, or clear it.
* @dev Empty is legitimate and is not the same as absent-and-wrong: a certificate authority has no
* encapsulation stage, and a certificate may be issued without one. The parser has already refused
* the half-populated case, so by here the pair is both or neither.
*
* Cleared rather than left alone on a rotation to an empty pair. A stale key surviving a rotation is
* a sender encapsulating to a credential the account has disowned, and the message then never
* decrypts — the failure mode with no error attached, and the one this pairing exists to avoid.
* @param account The identity being written.
* @param isCa Whether the record is a certificate authority, which carries no encapsulation stage.
* @param mlKem The stage's ML-KEM-1024 key, or empty.
* @param hqc The stage's HQC-5 key, or empty.
* @param isLive Whether this is the live stage; false selects the recovery slots.
*/
function _storeKemPair(address account, bool isCa, bytes memory mlKem, bytes memory hqc, bool isLive)
private
{
if (isCa || mlKem.length == 0) {
delete (isLive ? _activeKemMlKem : _recoveryKemMlKem)[account];
delete (isLive ? _activeKemHqc : _recoveryKemHqc)[account];
return;
}
if (!FinalChainPrecompiles.isWellFormedMlKem1024(mlKem)) {
revert MalformedEncapsulationKey(account, FinalCertificate.ALG_ML_KEM_1024);
}
if (!FinalChainPrecompiles.isWellFormedHqc5(hqc)) {
revert MalformedEncapsulationKey(account, FinalCertificate.ALG_HQC_5);
}
if (isLive) {
_activeKemMlKem[account] = mlKem;
_activeKemHqc[account] = hqc;
} else {
_recoveryKemMlKem[account] = mlKem;
_recoveryKemHqc[account] = hqc;
}
}
/// @notice Grant or withdraw capabilities without rotating keys.
/// @dev Separate from registration because the two have different cadences: a role changes when a
/// service's job changes, a key changes when it is compromised or aged out. Folding them together
/// would force a key rotation to express a role change, which is the more dangerous of the two
/// operations doing the work of the safer one.
/// @param account Must already be registered and not revoked.
/// @param roles The complete new capability bitmask; it replaces the old one rather than merging.
/// @param anchorBlock The block the registrars read the roster at.
/// @param approvals The sealed registrar quorum. Empty while bootstrap is open.
function setRoles(
address account,
uint256 roles,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireMembershipAuthority(
DOMAIN_SET_ROLES, keccak256(abi.encode(account, roles)), anchorBlock, approvals
);
Identity storage id = _identity[account];
if (!id.registered) revert UnknownAccount(account);
if (id.revoked) revert CertificateIsRevoked(id.certHash);
uint256 previous = id.roles;
id.roles = roles;
_requireRegistrarQuorumReachable();
emit IdentityRolesChanged(account, previous, roles);
// Roles are not in the tree-8 leaf, so this rewrites the same value —
// kept anyway so "every identity mutation projects" has no exceptions
// to remember.
_projectIdentity(account);
}
/// @notice Refuse a mutation that would leave the registrar quorum unreachable.
/// @dev Once bootstrap is sealed, that is the one change nothing could ever undo: a registry whose
/// threshold exceeds its sealable membership can never be written to again, including to fix
/// itself. Checked AFTER the write so the count reflects the mutation being attempted.
function _requireRegistrarQuorumReachable() private view {
if (!bootstrapSealed) return;
uint256 sealable = sealableMemberCount(ROLE_REGISTRAR);
if (sealable < registrarThreshold) {
revert RegistrarThresholdUnreachable(sealable, registrarThreshold);
}
}
/// @notice Revoke an identity and its certificate. Irreversible.
/// @dev Clears the roles as well as setting the flag. Both are checked everywhere, but leaving a revoked
/// record carrying roles invites a future reader that checks only one of them. The fingerprints of
/// the named LMS slots are recorded into the revocation log after the flag lands, so the log's own
/// permanence gate sees the transition it requires.
/// @param account The identity to retire.
/// @param chainIds The chains whose LMS-key slots this account holds. The registrars supply the list and
/// the approval digest binds it, because a mapping cannot enumerate its own keys. A chain with no
/// slot is skipped, and a fingerprint an incomplete list missed stays permanently recordable
/// through the revocation log's permissionless door, since a revoked account never regains
/// standing.
/// @param anchorBlock The block the registrars read the roster at.
/// @param approvals The sealed registrar quorum. Empty while bootstrap is open.
function revoke(
address account,
uint64[] calldata chainIds,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireMembershipAuthority(
DOMAIN_REVOKE, keccak256(abi.encode(account, chainIds)), anchorBlock, approvals
);
Identity storage id = _identity[account];
if (!id.registered) revert UnknownAccount(account);
id.revoked = true;
id.roles = 0;
certificateRevoked[id.certHash] = true;
_requireRegistrarQuorumReachable();
emit IdentityRevoked(account, id.certHash);
// AFTER the flag lands, so the log's own gate sees the permanent
// transition it requires.
for (uint256 i = 0; i < chainIds.length; i++) {
LmsKey storage k = _lmsKey[account][chainIds[i]];
if (k.registered) _recordRevokedSigner(lmsSignerId(k.keyId, k.height, k.root));
}
_projectIdentity(account);
}
/**
* @notice Root-plane GLOBAL certificate revocation, by `certHash`.
* @dev The half of the revocation lane that gates registration and covers break-glass: any certificate —
* registered here, issued off chain, or never seen — can be killed by handle under the registrar
* quorum, because the handle is all a break-glass caller may have.
*
* When the handle is a registered identity's CURRENT certificate the identity falls with it: flag,
* roles cleared, same-transaction projection. So revoking by handle is never weaker than {revoke};
* it only skips the LMS-slot enumeration, and those fingerprints stay permanently recordable
* through the revocation log's own permissionless door.
* @param certHash The certificate to revoke. Need not correspond to any record.
* @param anchorBlock The block the registrars read the roster at.
* @param approvals The sealed registrar quorum. Empty while bootstrap is open.
*/
function revokeCertificate(
bytes32 certHash,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireMembershipAuthority(
DOMAIN_REVOKE_CERTIFICATE, keccak256(abi.encode(certHash)), anchorBlock, approvals
);
certificateRevoked[certHash] = true;
address bound = accountOfCertificate[certHash];
if (bound != address(0)) {
Identity storage id = _identity[bound];
if (!id.revoked) {
id.revoked = true;
id.roles = 0;
_requireRegistrarQuorumReachable();
emit IdentityRevoked(bound, certHash);
_projectIdentity(bound);
}
}
emit CertificateRevoked(certHash, address(0));
}
/**
* @notice The issuing identity's half of the revocation lane: a registered issuer revokes a certificate
* it signed off chain, by `certHash`.
* @dev This records WHO revoked, and a verifier honours the entry only when the recorded revoker is the
* certificate's own issuer — which the verifier knows, because it holds the certificate. It
* deliberately does NOT set the global `certificateRevoked` flag: that flag gates registration, and
* letting any registered issuer set it for an arbitrary handle would be a griefing lane over other
* people's certificates.
*
* Anyone may SUBMIT. Authority is the two signatures — the issuer's registered cert-signing keys
* over a digest binding this registry, this chain, the handle and the issuer's own gate nonce, both
* verified in the precompiles inside this transaction. The keys come from storage, so a submitter
* cannot supply the pair its own signatures verify under.
*
* One-way: the first revoker of a handle is recorded and a second write is refused, because
* "revoked twice by two parties" is two facts where this lane models one.
* @param issuer The registered certificate authority making the statement.
* @param certHash The certificate being revoked.
* @param proof The issuer's own ML-DSA-87 and SLH-DSA-SHAKE-256s signatures over the revocation digest.
*/
function revokeIssuedCertificate(
address issuer,
bytes32 certHash,
AdmissionProof calldata proof
) external {
if (!hasRole(issuer, ROLE_CERTIFICATE_AUTHORITY)) {
revert IssuerNotACertificateAuthority(issuer);
}
if (certificateRevokedBy[certHash] != address(0)) revert CertificateIsRevoked(certHash);
uint64 nonce = _gateNonce[issuer];
_gateNonce[issuer] = nonce + 1;
bytes memory message = abi.encodePacked(
keccak256(
abi.encode(
DOMAIN_ISSUER_CERT_REVOCATION,
block.chainid,
address(this),
issuer,
certHash,
nonce
)
)
);
if (
!FinalChainPrecompiles.verifyMlDsa87(
_activeTransactionKey[issuer], message, proof.mlDsaSignature
)
|| !FinalChainPrecompiles.verifySlhDsa(
_activeAccessKey[issuer], message, proof.slhDsaSignature
)
) revert AdmissionProofInvalid(issuer);
certificateRevokedBy[certHash] = issuer;
emit CertificateRevoked(certHash, issuer);
}
// ---------------------------------------------------------------- views
/// @notice The full identity record.
/// @dev Returns the zero struct for an address no record claims, so `registered` is the field to branch
/// on rather than any of the hashes.
/// @param account The identity to read.
/// @return The stored record, copied to memory.
function identityOf(address account) external view returns (Identity memory) {
return _identity[account];
}
/// @notice The live transaction key, ML-DSA-87: what a quorum vote is verified against.
/// @dev Read from STORAGE by every quorum on this chain, never from a caller's argument — a key supplied
/// as calldata proves nothing, because anyone holding a keypair can sign under it.
/// @param account The identity to read.
/// @return The raw public key, or empty when the account holds none.
function activeTransactionKeyOf(address account) external view returns (bytes memory) {
return _activeTransactionKey[account];
}
/// @notice The live access key, SLH-DSA-SHAKE-256s: identity, rotation, and guardianship.
/// @dev A different hardness assumption from the transaction key, so a lattice break leaves the key that
/// governs identity standing intact.
/// @param account The identity to read.
/// @return The raw public key, or empty when the account holds none.
function activeAccessKeyOf(address account) external view returns (bytes memory) {
return _activeAccessKey[account];
}
/// @notice The seal key, SLH-DSA-SHAKE-256s: what `FinalPqQuorum` verifies an approval's seal against.
/// @dev A service's second hash-based key, distinct from its access key, so a quorum decision carries
/// one signature from each hardness assumption. Empty when the identity carries no seal, in which
/// case it cannot take part in a sealed quorum at all — which is why {sealableMemberCount} counts
/// this rather than counting role bits.
/// @param account The identity to read.
/// @return The raw public key, or empty when the account holds no seal.
function activeSealKeyOf(address account) external view returns (bytes memory) {
return _activeSealKey[account];
}
/// @notice The recovery-stage transaction key, ML-DSA-87.
/// @dev Authorizes rotating this account's own credentials and nothing else — acting as a guardian is an
/// ordinary action for an account and uses the live keys. Empty for a certificate authority.
/// @param account The identity to read.
/// @return The raw public key, or empty when the account holds none.
function recoveryTransactionKeyOf(address account) external view returns (bytes memory) {
return _recoveryTransactionKey[account];
}
/// @notice The recovery-stage access key, SLH-DSA-SHAKE-256s.
/// @dev The other half of the pre-committed recovery stage. Empty for a certificate authority, which has
/// no recovery stage at all.
/// @param account The identity to read.
/// @return The raw public key, or empty when the account holds none.
function recoveryAccessKeyOf(address account) external view returns (bytes memory) {
return _recoveryAccessKey[account];
}
/// @notice The four signing-key commitments, in the order tree 1's leaf wants them.
/// @dev keccak, not SHA3: these feed `FinalWalletFactory.accountStateLeafHash`, which every execution
/// chain verifies with, and that one hashes with keccak. An account missing a slot commits to the
/// hash of the empty string rather than reverting, so the leaf stays buildable for a certificate
/// authority, which holds no recovery pair.
/// @param account The identity to commit to.
/// @return liveAccess Commitment to the live access key.
/// @return liveTransaction Commitment to the live transaction key.
/// @return recoveryAccess Commitment to the recovery access key.
/// @return recoveryTransaction Commitment to the recovery transaction key.
function keyCommitments(address account)
external
view
returns (
bytes32 liveAccess,
bytes32 liveTransaction,
bytes32 recoveryAccess,
bytes32 recoveryTransaction
)
{
liveAccess = keccak256(_activeAccessKey[account]);
liveTransaction = keccak256(_activeTransactionKey[account]);
recoveryAccess = keccak256(_recoveryAccessKey[account]);
recoveryTransaction = keccak256(_recoveryTransactionKey[account]);
}
/**
* @notice The tree-8 leaf `account` currently earns: the execution chains' identity leaf while the
* identity stands, zero once it does not.
* @dev The leaf VALUE is `keccak256(DOMAIN_IDENTITY_LEAF ‖ serial ‖ keysHash)` — byte-identical to
* `IdentityRootModule.identityLeafHash`, which is also the `certHash` inside a wallet's address
* derivation — with `keysHash` folded exactly as the certificate issuer folds it:
* `keccak256(activeAccess ‖ activeTransaction ‖ recoveryAccess ‖ recoveryTransaction ‖ activeKem ‖
* recoveryKem)`, six commitment words packed in slot order. The issuing tooling and this function
* are pinned against each other by test over the premined certificate fixtures, because a wallet
* whose address was derived from a different fold is a wallet no chain can admit.
*
* Zero — the empty slot's own value, unprovable as a leaf because no certificate hashes to it — for
* anything that must not admit a wallet creation: a revoked identity, one outside its validity
* window, and any certificate authority. The authority exclusion is STRUCTURAL rather than a role
* read: an end entity has `depth == maxDelegationDepth` because it issues nothing, an authority
* never does, and that pair is immutable per version where `roles` is not.
*
* Lives here rather than on the state-trees contract that consumes it because every input is this
* contract's storage, and the trees contract has no bytecode headroom to spare.
* @param account The identity to project. Reverts for an account with no record at all.
* @return The tree-8 leaf value, or zero while the identity does not stand.
*/
function identityTreeLeafOf(address account) external view returns (bytes32) {
Identity storage id = _identity[account];
if (!id.registered) revert UnknownAccount(account);
if (id.revoked || !_withinValidity(id)) return bytes32(0);
if (id.depth != id.maxDelegationDepth) {
// An ISSUER exists in tree 8 under its own domain, so its record is stapleable for offline
// licence verification while the distinct domain keeps it out of wallet admission. `certHash`
// suffices — it covers the whole TBS and the verifier holds the certificate — `version` makes
// supersession move the leaf, and the third word RESERVES the issuer's own certificate-tree
// anchor, zero until one is wired. Zero-on-revoke above is load-bearing for both record kinds:
// a fresh staple is an unrevoked statement.
return keccak256(
abi.encodePacked(DOMAIN_ISSUER_LEAF, id.certHash, uint64(id.version), bytes32(0))
);
}
bytes32 liveKem = keccak256(
abi.encodePacked(DOMAIN_KEM_BUNDLE, _activeKemMlKem[account], _activeKemHqc[account]));
bytes32 recoveryKem = keccak256(
abi.encodePacked(DOMAIN_KEM_BUNDLE, _recoveryKemMlKem[account], _recoveryKemHqc[account]));
bytes32 keysHash = keccak256(
abi.encodePacked(
keccak256(_activeAccessKey[account]),
keccak256(_activeTransactionKey[account]),
keccak256(_recoveryAccessKey[account]),
keccak256(_recoveryTransactionKey[account]),
liveKem,
recoveryKem
)
);
return keccak256(abi.encodePacked(DOMAIN_IDENTITY_LEAF, id.serial, keysHash));
}
/// @notice Per-stage encapsulation commitments, in the order the account-state leaf wants them.
/// @dev One word per STAGE, folded over both of that stage's encapsulation public keys under
/// `DOMAIN_KEM_BUNDLE`. The pair is the unit — an account holds both keys or neither — so
/// committing to them separately would model a state the protocol does not recognise, and every
/// downstream record would carry two words where one says the same thing.
///
/// An account whose certificate carries no encapsulation stage folds the empty string here rather
/// than reverting: the projection into the state trees must keep succeeding for it, and a leaf that
/// cannot be built is a party that cannot be revoked.
/// @param account The identity to commit to.
/// @return liveKem The live stage's encapsulation commitment.
/// @return recoveryKem The recovery stage's encapsulation commitment.
function kemCommitments(address account)
external
view
returns (bytes32 liveKem, bytes32 recoveryKem)
{
liveKem = keccak256(
abi.encodePacked(DOMAIN_KEM_BUNDLE, _activeKemMlKem[account], _activeKemHqc[account]));
recoveryKem = keccak256(
abi.encodePacked(DOMAIN_KEM_BUNDLE, _recoveryKemMlKem[account], _recoveryKemHqc[account]));
}
/// @notice The live-stage encapsulation keys themselves, for a party composing a sealed message.
/// @dev Returns both halves of the pair together because the pair is the unit: encapsulating to one
/// family alone is indistinguishable on the wire from a hybrid, and silently dropping the hedge is
/// the failure this pairing exists to prevent. Empty for an account with no encapsulation stage.
/// @param account The party to encapsulate to.
/// @return activeMlKem The lattice half, ML-KEM-1024.
/// @return activeHqc The code-based half, HQC-5.
function kemKeysOf(address account)
external
view
returns (bytes memory activeMlKem, bytes memory activeHqc)
{
return (_activeKemMlKem[account], _activeKemHqc[account]);
}
// ------------------------------------------------------------- senders
/**
* @notice The sender address a transaction key produces on this chain.
* @dev `keccak256(uint8(4) ‖ publicKey)[12:]` — byte-identical to what the node derives from a
* post-quantum transaction envelope and to the backend's own derivation. The leading algorithm byte
* is what domain-separates it, so a key of another family can never derive the same address.
*
* Pure, so a client can compute the address from a certificate before the identity is registered —
* which is what lets an admission transaction be funded and submitted from the very sender it is
* about to bind.
* @param transactionKey The raw ML-DSA-87 public key.
* @return The sender address that key signs from.
*/
function senderFor(bytes memory transactionKey) public pure returns (address) {
return address(uint160(uint256(keccak256(abi.encodePacked(ENVELOPE_ALG_ML_DSA_87, transactionKey)))));
}
/// @notice The sender `account`'s transactions arrive from.
/// @dev The forward direction of {accountOfSender}, derived rather than stored, so it cannot disagree
/// with the transaction key on record.
/// @param account The identity to resolve.
/// @return The derived sender, or zero for an account with no transaction key on record.
function senderOf(address account) external view returns (address) {
bytes storage key = _activeTransactionKey[account];
if (key.length == 0) return address(0);
return senderFor(key);
}
/// @notice {hasRole} for a `msg.sender`: resolves the sender to its identity first.
/// @dev The form every `msg.sender` gate on this chain uses. A sender is derived from a transaction key
/// and holds no authority itself, so asking it directly would be asking the wrong address. False for
/// a sender no identity claims.
/// @param sender The address a transaction arrived from.
/// @param roleMask The capability required.
/// @return Whether the identity behind that sender stands and carries the whole mask.
function senderHasRole(address sender, uint256 roleMask) external view returns (bool) {
address account = accountOfSender[sender];
return account != address(0) && hasRole(account, roleMask);
}
/// @notice How many accounts carrying `roleMask` also hold a seal key — the members that can take part
/// in a sealed quorum.
/// @dev The count every membership threshold is checked against, because membership approvals are the
/// hybrid class and a member with no seal can never contribute one. A certificate authority
/// carrying `ROLE_REGISTRAR` is registered from a certificate with no seal slot, so it is counted
/// out here rather than being discovered at the first quorum that fails to reach its threshold.
/// @param roleMask The capability the quorum is over.
/// @return sealable How many standing accounts carry the mask and hold a seal key.
function sealableMemberCount(uint256 roleMask) public view returns (uint256 sealable) {
uint256 n = _accounts.length;
for (uint256 i = 0; i < n; i++) {
address a = _accounts[i];
if (hasRole(a, roleMask) && _activeSealKey[a].length != 0) sealable++;
}
}
/// @notice Number of registered accounts.
/// @dev Never decreases: revocation clears a record's roles and sets its flag but leaves it in the list,
/// so an index handed out once keeps pointing at the same account for good.
/// @return How many accounts have ever been registered.
function accountCount() external view returns (uint256) {
return _accounts.length;
}
/// @notice Registered account by index, in registration order.
/// @dev Reverts on an out-of-range index rather than answering zero, so a caller paging the list cannot
/// mistake the end of it for a hole in the middle.
/// @param index Position in the registration-ordered list, below {accountCount}.
/// @return The account at that position.
function accountAt(uint256 index) external view returns (address) {
return _accounts[index];
}
/// @notice Every account carrying every bit in `roleMask`.
/// @dev A view, so the linear scan over the account list costs nothing to a caller reading off chain.
/// Callers that need a roster inside a transaction pass the member list explicitly instead — see
/// `FinalPqQuorum`, which takes signers rather than searching for them, so a quorum's cost does not
/// grow with the size of the registry.
/// @param roleMask The capability to filter on.
/// @return found The matching accounts, in registration order.
function accountsWithRole(uint256 roleMask) external view returns (address[] memory found) {
uint256 n = _accounts.length;
address[] memory buf = new address[](n);
uint256 count;
for (uint256 i = 0; i < n; i++) {
if (hasRole(_accounts[i], roleMask)) {
buf[count++] = _accounts[i];
}
}
found = new address[](count);
for (uint256 i = 0; i < count; i++) {
found[i] = buf[i];
}
}
/**
* @notice How many accounts could satisfy a quorum for `roleMask` right now.
* @dev The number a threshold has to be reachable against. A threshold above it is not a strict quorum,
* it is a quorum that cannot be met — and the way that presents is an operation reverting forever
* with nothing naming the roster as the cause. Counts standing alone; use {sealableMemberCount} for
* a quorum that also needs a seal.
* @param roleMask The capability the quorum is over.
* @return live How many standing accounts carry the whole mask.
*/
function liveMemberCount(uint256 roleMask) public view returns (uint256 live) {
uint256 n = _accounts.length;
for (uint256 i = 0; i < n; i++) {
if (hasRole(_accounts[i], roleMask)) live++;
}
}
/**
* @notice Whether `account` currently carries every bit in `roleMask`.
* @dev Every gate in this system asks this one question, so every gate gets the same answer: registered,
* not revoked, inside its validity window, and holding the capability. A caller that checked only
* the role bit would accept an expired certificate.
*
* `roleMask == 0` is false. A zero mask asks nothing and must not read as "yes" — that is the shape
* of an uninitialised configuration variable, and the one reading it must not be a universal pass.
*
* Every bit in the mask must be present, so a mask naming two capabilities asks for both rather than
* either.
* @param account The account to test.
* @param roleMask One or more `ROLE_*` bits, OR-ed together.
* @return Whether the account stands and carries the whole mask.
*/
function hasRole(address account, uint256 roleMask) public view returns (bool) {
if (roleMask == 0) return false;
Identity storage id = _identity[account];
if (!id.registered || id.revoked) return false;
if (id.roles & roleMask != roleMask) return false;
return _withinValidity(id);
}
/// @notice Whether `account` is registered, unrevoked and in date, regardless of capability.
/// @dev The standing half of {hasRole}, for callers that care that a party is honoured at all rather
/// than that it holds a particular capability. {lmsSignerIsLive} asks this rather than spelling the
/// three conditions out a second time, because a second spelling is how two answers drift apart.
/// @param account The account to test. An address no record claims answers false.
/// @return Whether the identity currently stands.
function isActive(address account) public view returns (bool) {
Identity storage id = _identity[account];
return id.registered && !id.revoked && _withinValidity(id);
}
/// @notice Whether a record's certificate is inside its validity window right now.
/// @dev Both bounds are milliseconds on this chain's clock and both are optional: a zero `notBefore`
/// means valid from issuance and a zero `notAfter` means never expires, which the certificate
/// schema allows and personal identity certificates use. The upper bound is exclusive, so a
/// certificate stops being honoured on the millisecond it names rather than after it.
/// @param id The record to test, taken as a storage pointer so no copy of a multi-word struct is made.
/// @return Whether the window admits the current block time.
function _withinValidity(Identity storage id) private view returns (bool) {
if (id.notBefore != 0 && FinalChainTime.nowMs() < id.notBefore) return false;
if (id.notAfter != 0 && FinalChainTime.nowMs() >= id.notAfter) return false;
return true;
}
// ------------------------------------------------------------------ sweep
/// @inheritdoc FinalSweep
/// @dev The registry's own configuration gate, in the `msg.sender` form a no-argument seam can express:
/// the bootstrap admin alone while the window is open, a live registrar afterwards.
///
/// The rest of the state plane inherits this rule from `FinalPlaneSweep`, which reads it off a
/// registry pointer. This contract answers it from its own storage because it IS that registry, and
/// importing the shared mixin here would make this file import a file that imports it back.
///
/// The sealed half of the gate is a K-of-N over `ROLE_REGISTRAR` whose approvals arrive in calldata,
/// which `sweepAsset`'s shared signature has no room for; what survives is membership in that same
/// roster. The narrowing is safe because the other two gates hold regardless: a sweep moves surplus
/// only, this contract owes nothing, so there is nothing behind the line to reach — and the
/// destination is not the caller's to invent.
function _requireSweepAuthority() internal view override {
if (!bootstrapSealed && msg.sender == bootstrapAdmin) return;
if (hasRole(msg.sender, ROLE_REGISTRAR)) return;
revert SweepUnauthorized(msg.sender);
}
/// @inheritdoc FinalSweep
/// @dev The bootstrap admin, and the proven authority that called. The first of those is zero once the
/// window is sealed, which `FinalSweep` refuses as a destination, so a sealed registry can only
/// sweep to the registrar that authorised the sweep.
function _sweepDestinations() internal view override returns (address, address) {
return (bootstrapAdmin, msg.sender);
}
/// @dev Nothing is reserved because nothing is owed: the registry holds
/// certificates and role bits, has no payable entrypoint and no custody
/// line. Anything it carries arrived by accident.
}
contracts/finalchain/FinalIntentLog.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may deploy and operate this intent log as part of a
// Final DeFi Protocol chain, and may record intent status in it under the
// authority the chain recognises.
// 2. Integrators, relayers, and indexers may read the intent status it
// mirrors and search it by its ring keys, as part of their integration
// with the Final DeFi Protocol.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this intent log or a competing intent-status
// plane derived from it without permission prior to the Change Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
import {FinalChainPrecompiles} from "./FinalChainPrecompiles.sol";
import {FinalChainTime} from "./FinalChainTime.sol";
import {FinalIdentityRegistry} from "./FinalIdentityRegistry.sol";
import {FinalPqQuorum} from "./FinalPqQuorum.sol";
import {FinalStateTrees} from "./FinalStateTrees.sol";
import {FinalPlaneSweep} from "./FinalPlaneSweep.sol";
import {SweepKind} from "../utils/FinalSweep.sol";
/**
* @title FinalIntentLog
* @notice Every intent is posted here before it may be anchored. Ordering is
* block order.
*
* @dev ## Why this is a log and not a tree
*
* Final Chain carries six trees, and they publish in ROUNDS — every root
* together, one version bump each. That structure is for state that changes
* slowly and must be proven elsewhere. An intent is neither: it is high
* cadence, it lives 180 seconds, and putting it in a round-published tree would
* bump a version on every transaction and age every outstanding proof — the
* same objection that kept a liveness timestamp out of the tree-1 account leaf.
*
* It is not an MMR either. `FinalBundleLog`'s payload already IS the bundle's
* intent-Merkle root, so a second append-only log over the same leaves would
* prove, one level earlier, a fact the bundle anchor already proves.
*
* What an intent actually needs is ordering, public availability, and a
* presence check the anchoring quorum can run objectively. Block order gives
* the first, calldata gives the second, and a mapping gives the third. That is
* the whole contract.
*
* ## What it buys
*
* `FinalBundleLog.append` consumes from here, so a bundle cannot be anchored
* unless every intent in it was posted first — and the execution chains'
* authorization is that anchor. Final-Chain-first admission stops being a
* quorum policy and becomes bytecode. Replay protection falls out of the same
* mapping: a leaf is consumed exactly once, ever.
*
* For the user it closes substitution. The intent they composed is ordered
* publicly before anything executes, so a relayer or a frontend cannot swap it
* for another — the anchor will only carry what this log holds.
*
* ## The body is encrypted and this contract cannot read it
*
* `header` is routing metadata: a chain reference, a deadline, KEM ciphertexts,
* a commitment to the body, and the intent leaf. Account, destination, fee and
* calldata are all inside `ciphertext`. That is what closes content-based
* front-running — an operator watching this log sees a chain id and a deadline
* and cannot build a profitable order from either.
*
* There is deliberately no decryption path on chain and no AEAD precompile. The
* chain checks a hash and nothing else.
*
* ## The envelope is STORED, not left in the event log
*
* A two-KEM envelope is ~16 KB and keeping it in state is not free. It is kept
* anyway, for the reason `FinalBundleLog` keeps its payloads: this chain caps a
* `getLogs` range at 100,000 blocks and mints one every 100 ms, so the log is
* reachable for **2.8 hours**. A forced-path intent lives **48**.
*
* An event-only envelope would therefore be unreadable long before it expired —
* precisely for the guardians who are meant to review a forced intent, and
* precisely in the window the forced path exists to cover. That is not a
* degraded read, it is the escape hatch not working.
*
* So the event is for DISCOVERY and carries no bytes; state is for retrieval,
* over one `eth_call` and no range. Emitting the envelope as well would be
* ~128k gas of duplication for data the same transaction already stored.
*
* Measured in `FinalIntentLog.t.sol`: **11,517,049 gas** for a 16,426-byte
* envelope, which at a 60M block gas limit is **5 intents per block** — 50 a
* second at 100 ms. That is the throughput ceiling on this path, and it is
* dominated by HQC-5's 14,421-byte ciphertext.
*
* Two levers if it ever binds. SSTORE2-style data contracts are ~3x cheaper per
* byte, and would need chunking because a two-recipient envelope exceeds
* EIP-170's 24,576. Pruning consumed envelopes is the other, and it trades the
* record for the space — a decision, not a cleanup.
*
* **The bond becomes load-bearing when the RPC opens, not before.** Posting is
* permissionless in this contract and the base fee is 1 wei, so the only thing
* standing between an attacker and 60M gas a block of permanent state is that
* Final Chain's RPC is fronted by a default-deny Cloud Armor allowlist and
* reaches operators only. That is a perimeter, not a mechanism, and it is the
* one that has to be removed for users to post their own intents. Nothing here
* rate-limits; the bond is what is supposed to, and this is why it cannot ship
* after the RPC does.
*
* ## Approve and cancel, without naming an account
*
* An approval-gated intent executes only after a second on-chain act, made
* after the user decrypts the posted envelope and reads what the CHAIN holds —
* the read-back that closes execution of what the user has not seen. Who may
* approve is a **per-intent, wallet-generated ML-DSA-87 key**, committed in the
* plaintext header: the commitment names a key, never an account, which is what
* answers "a per-intent veto has to say who may veto, and the account is
* encrypted". A substituted commitment strands the intent — the execution
* signature bound into the leaf still authorizes every field — and cancel is
* the same key, any time before consumption.
*
* `approve` also DELIVERS the executor section: the content key and the
* account's KEM public keys, sealed to the executor set. Before approval the
* executor holds ciphertext it cannot open; that is cryptography, not policy.
* An AUTO_APPROVE posting (header flag, bit 0) skips the gate for automation
* and scheduling and carries its executor section at posting — flipping the
* flag skips the second look and can never change what executes.
*
* The account-wide veto stays `FinalAccountLedger`'s freeze; auto-approved
* intents have no per-intent cancel because they commit to no approval key.
*
* ## Tree 7 is the search structure; the MMR is the record
*
* Every transition — posted, approved, cancelled, consumed — is mirrored into
* `FinalStateTrees.TREE_INTENTS` through `treeWriter[7]`, keyed by a RING over
* the posting sequence (`seq mod 2^20`), so slots recycle and the tree is an
* index with a ~1M-posting retention window rather than a permanent record.
* Backends enumerate it instead of scanning logs; proofs against it are proofs
* about the current window.
*/
contract FinalIntentLog is FinalPlaneSweep {
/// @notice Where roles are resolved. Immutable.
///
/// @dev The only thing this log needs a registry for is authorizing
/// `setConsumer`, and that could have been a deployer check. It is the
/// registry instead so the wiring falls under the SAME bootstrap window
/// as `FinalStateTrees.setTreeWriter` and `FinalBundleLog.configure` —
/// one rule for who may wire Final Chain together, rather than three.
FinalIdentityRegistry public immutable registry;
/// @notice Where every status transition is mirrored (tree 7). Immutable:
/// a movable index would be an index whose history can be swapped.
FinalStateTrees public immutable trees;
/// @dev Header layout, fixed offsets. Must match `encodeHeader` in
/// `FinalBackend/src/intents/intentEnvelope.js` — the cross-repo parity
/// suite pins it. Length-prefixed and canonical precisely so these
/// offsets exist: a JSON header would have no stable position to read.
///
/// 0 version uint8 = 2 | 3 (v3 salts recipientsHash; offsets identical)
/// 1 flags uint8 bit0 AUTO_APPROVE; rest zero
/// 2..33 targetChainRef bytes32
/// 34..41 executeNotBefore uint64 ms; 0 = immediate
/// 42..49 deadline uint64 ms
/// 50..81 bodyCommitment bytes32
/// 82..113 intentLeaf bytes32
/// 114..145 approvalKeyCommit bytes32 zero iff AUTO_APPROVE
/// 146..147 kemSet uint16
/// 148..149 kemKeyVersion uint16
/// 150..181 recipientsHash bytes32
/// 182.. recipients, executorSection, bond
uint256 private constant OFF_FLAGS = 1;
/// @dev Byte offset of `targetChainRef` in the packed intent header. The header is
/// read by offset rather than decoded,
/// so every offset here must match what the header's producers write, byte for byte.
uint256 private constant OFF_TARGET_CHAIN_REF = 2;
/// @dev Byte offset of `executeNotBefore` in the packed intent header. The header is
/// read by offset rather than decoded,
/// so every offset here must match what the header's producers write, byte for byte.
uint256 private constant OFF_EXECUTE_NOT_BEFORE = 34;
/// @dev Byte offset of `deadline` in the packed intent header. The header is
/// read by offset rather than decoded,
/// so every offset here must match what the header's producers write, byte for byte.
uint256 private constant OFF_DEADLINE = 42;
/// @dev Byte offset of `bodyCommitment` in the packed intent header. The header is
/// read by offset rather than decoded,
/// so every offset here must match what the header's producers write, byte for byte.
uint256 private constant OFF_BODY_COMMITMENT = 50;
/// @dev Byte offset of `intentLeaf` in the packed intent header. The header is
/// read by offset rather than decoded,
/// so every offset here must match what the header's producers write, byte for byte.
uint256 private constant OFF_INTENT_LEAF = 82;
/// @dev Byte offset of `approvalKeyCommitment` in the packed intent header. The header is
/// read by offset rather than decoded,
/// so every offset here must match what the header's producers write, byte for byte.
uint256 private constant OFF_APPROVAL_KEY_COMMIT = 114;
/// @dev The whole fixed prefix, including `recipientsHash` — which this
/// contract never reads. Requiring it anyway is the cheap half of
/// "well-formed": a header truncated after the leaf would parse
/// perfectly here and then fail to decrypt for its recipient. The
/// contract reads nothing past offset 145.
uint256 private constant HEADER_MIN_BYTES = 182;
/// @notice The oldest envelope wire version this contract reads.
uint8 public constant HEADER_VERSION = 2;
/// @notice The newest. v3 keeps every offset and salts `recipientsHash`
/// — a field this contract never reads — with a holder-derived value,
/// so a wallet's postings stop sharing a fingerprint in the clear.
/// Both versions parse identically here; the header's own AAD is what
/// tells them apart for the recipients.
uint8 public constant HEADER_VERSION_MAX = 3;
/// @notice Header flag bit 0: skip the approval gate.
/// @dev Poster-controlled routing, honestly scoped: flipping it skips the
/// user's second look and can never change what executes — the user's own
/// signature over the intent fields, bound into the leaf, remains the only
/// execution authorization.
uint8 public constant FLAG_AUTO_APPROVE = 0x01;
// ---------------------------------------------------- approval domains
/// @dev Distinct per action, so an approval can never be replayed as a
/// cancellation or vice versa. Both digests bind this chain and this log.
bytes32 public constant DOMAIN_INTENT_APPROVE = keccak256("FINAL_INTENT_APPROVE_v01");
/// @notice Domain tag for a cancellation digest.
/// @dev Separate from every other tag, so a signature collected to cancel one intent cannot be replayed as
/// an approval of anything.
bytes32 public constant DOMAIN_INTENT_CANCEL = keccak256("FINAL_INTENT_CANCEL_v01");
// ------------------------------------------------------ tree-7 mirror
/// @dev The ring key's domain. Named in `FinalStateTrees`' key.* family
/// because that is the space it lives in; computed HERE because the log is
/// the writer and the backend mirrors this function, not the tree.
bytes32 public constant DOMAIN_INTENT_KEY = keccak256("FinalStateTrees.key.intent.v01");
/// @dev The status leaf's domain.
bytes32 public constant DOMAIN_INTENT_STATUS_LEAF = keccak256("FINAL_INTENT_STATUS_LEAF_v01");
/// @notice Ring size: keys recycle at `CAPACITY`, so the tree can never
/// fill however long the chain runs. Pinned equal to
/// `FinalStateTrees.CAPACITY` by test.
uint64 public constant INTENT_SLOT_RING = uint64(1) << 20;
/// @notice The tree this log writes. Restated from `FinalStateTrees`
/// because a contract-type constant is not reachable here; pinned equal to
/// `trees.TREE_INTENTS()` by test.
uint8 public constant TREE_INTENTS_ID = 7;
/// @notice The branch the intent ring lives in — `FinalStateTrees.BRANCH_MAIN`,
/// pinned by test. Branch 0 of tree 7 is the log's configuration.
uint8 public constant BRANCH_MAIN_ID = 1;
/// @notice Tree-7 status values.
uint8 public constant STATUS_POSTED = 1;
/// @notice Status: approved and awaiting consumption.
uint8 public constant STATUS_APPROVED = 2;
/// @notice Status: consumed. Terminal — a consumed intent is spent and cannot return to any other state.
uint8 public constant STATUS_CONSUMED = 3;
/// @notice Status: cancelled. Terminal, and recorded rather than erased, so a canceller can prove the intent
/// was withdrawn rather than never posted.
uint8 public constant STATUS_CANCELLED = 4;
/// @dev Registrar-quorum actions, verified by the registry with this log as
/// the verifying contract.
bytes32 public constant ACTION_SET_CONSUMER = keccak256("FINAL_INTENT_LOG_SET_CONSUMER_v01");
/// @notice Action tag for seeding the sequence of a fresh log.
bytes32 public constant ACTION_SEED_SEQUENCE = keccak256("FINAL_INTENT_LOG_SEED_SEQUENCE_v01");
/// @notice Action tag for setting the bond policy. Distinct from the seeding tag, so an approval collected
/// for one cannot perform the other.
bytes32 public constant ACTION_SET_BOND_POLICY = keccak256("FINAL_INTENT_LOG_SET_BOND_POLICY_v01");
/**
* @notice The longest an intent may stay consumable past its earliest
* execution moment.
*
* @dev A cap rather than an exact value because every lane shares this log,
* and an uncapped deadline would let a posting sit consumable forever —
* which is a replay window dressed as a long-lived intent. An immediate
* intent (`executeNotBefore == 0`) gets exactly this from `now`; a
* scheduled one gets it from its own start.
*/
/// @dev MILLISECONDS, like every duration on this chain. Its predecessor
/// was once 48 hours read against a millisecond clock — 48 SECONDS —
/// so a header whose deadline a client computed from wall time was
/// refused before it could ever be posted.
uint64 public constant EXECUTION_WINDOW = 48 hours * FinalChainTime.MS_PER_SECOND;
/// @notice How far ahead `executeNotBefore` may sit. The scheduling
/// horizon: chosen at signing, because the deadline is inside the signed
/// intent and cannot be extended afterwards.
uint64 public constant MAX_SCHEDULE_HORIZON = 30 days * FinalChainTime.MS_PER_SECOND;
/// @notice How far ahead of `executeNotBefore` a scheduled posting may be
/// CONSUMED when its target chain has no lead of its own — ninety
/// seconds, per target chain. Admission — the
/// co-signer round and the append that consumes the leaf — runs
/// before T, so the fleet can compose and broadcast the wrapper to
/// land in the first target-chain block at or after T rather than
/// minutes late. The holder's veto (`cancel`) closes at consume,
/// i.e. no earlier than T − lead: the lead is the last call for a
/// cancel. An immediate posting (`executeNotBefore == 0`) has no
/// lead. Per chain: a row in tree 7's CONFIGURATION branch
/// (`FinalStateTrees.setConfig`, key `configKey(CONFIG_SCHEDULE_LEAD_MS,
/// targetChainRef)`) overrides this default (`scheduleLeadMsOf`),
/// explicit zero included — the first tenant of the config branch.
uint64 public constant DEFAULT_SCHEDULE_LEAD_MS = 90 * FinalChainTime.MS_PER_SECOND;
/// @notice The config-row NAME of a target chain's schedule lead, in
/// milliseconds: `trees.configKey(CONFIG_SCHEDULE_LEAD_MS, targetChainRef)`
/// → one word holding the lead. Written under the configuration
/// authority (bootstrap admin, then the registrar quorum) — an
/// operational parameter, not a trust boundary — and PROVABLE like
/// every other row of the plane, which a table here was not.
bytes32 public constant CONFIG_SCHEDULE_LEAD_MS = keccak256("FinalIntentLog.config.scheduleLeadMs.v01");
struct Posted {
/// @dev Zero means never posted. Non-zero and `consumedAt == 0` means open.
uint64 postedAt;
/// @dev From the header, in MILLISECONDS. Before this, `consume` refuses.
uint64 executeNotBefore;
/// @dev From the header, in MILLISECONDS. After this, `consume` refuses.
uint64 deadline;
/// @dev Block timestamp of the anchoring append. Non-zero means spent.
uint64 consumedAt;
/// @dev `keccak256(body)` — the leaf↔body binding. With the reveal
/// schema gone it is checked OFF-chain: the execution chain's
/// public calldata against this word.
bytes32 bodyCommitment;
/// @dev `keccak256` of the per-intent approval public key; zero iff
/// AUTO_APPROVE. Names a key, never an account.
bytes32 approvalKeyCommit;
/// @dev From the header; kept for the tree-7 status leaf.
bytes32 targetChainRef;
/// @dev When `approve` verified. Non-zero means approved.
uint64 approvedAt;
/// @dev When `cancel` verified. Non-zero means dead: `consume` refuses.
uint64 cancelledAt;
/// @dev Posting sequence — the tree-7 ring position (`seq mod 2^20`).
uint64 seq;
/// @dev Header flags, verbatim.
uint8 flags;
}
/// @dev The bytes, kept apart from `Posted` on purpose. `consume` runs on
/// the anchoring path and reads only the packed record; it must never
/// pay to walk 16 KB it does not look at.
struct Envelope {
/// @dev Canonical header, exactly as posted.
bytes header;
/// @dev The sealed body. This contract cannot read it and never tries.
bytes ciphertext;
/// @dev The content key and the account's KEM public keys, sealed to
/// the executor set. Delivered by `approve` — so before approval
/// the executor holds ciphertext it cannot open — or present from
/// posting on an AUTO_APPROVE intent. Opaque here: this contract
/// stores it and never parses it.
bytes executorSection;
}
/// @notice Keyed by the intent LEAF, not by an envelope id.
///
/// @dev The leaf is what `FinalBundleLog` folds and what the execution
/// chain's gateway recomputes, so keying on it makes the presence check
/// exact. It also makes duplicate protection land on the right thing: a
/// second header carrying a leaf already posted is the same intent
/// offered twice, and is refused.
mapping(bytes32 leaf => Posted) public postedOf;
/// @notice The full envelope, retrievable for as long as the chain exists.
mapping(bytes32 leaf => Envelope) private _envelopeOf;
/// @notice Postings ever made. The next intent takes this as its `seq`.
uint64 public postSeq;
/// @notice The leaf posted at sequence `seq` — the enumeration the backend
/// walks (`postSeq` is the count) instead of a `getLogs` range.
mapping(uint64 => bytes32) public leafAt;
// ─────────────────────────── the per-vertex bond ───────────────────────────
//
// **Encrypting the account removes attribution, and attribution is what
// rate-limiting runs on.** Posting is permissionless at a 1 wei base fee and
// state spam does not age out the way calldata spam does, so the thing
// holding it off today is the default-deny allowlist on this chain's RPC —
// a perimeter, and precisely the one that has to come down for users to post
// their own intents. A bond charges the spammer regardless of identity,
// needs no new cryptography, and is the natural unit for operators paid per
// unit of work.
//
// Refunded on valid execution, forfeited on a vertex that was never
// anchored. Both are PULL: `consume` runs inside the anchoring append and
// must not be able to fail, or be delayed, because of where a refund was
// going.
//
// **Not in the header.** The header's `<authenticator>` field stays a
// free-form reference for off-chain accounting and is deliberately not the
// bond itself. Moving the bond into the header would be an encoding change
// rippling through every reader and the cross-repo offset parity, and a
// bond is not worth one when native value keyed by leaf says the same
// thing.
//
// **Zero is the shipped state**, which is today's behaviour exactly. Arming
// it is the step that must precede opening the RPC, not follow it.
struct Bond {
/// @dev Who paid, and who a refund goes back to. Not the intent's
/// account — that is encrypted and this contract cannot know it — which
/// is the whole reason a bond works here and a per-account quota does
/// not.
address payer;
/// @dev Wei paid. Stored rather than re-read from `bondWei`, because the
/// rate can move between posting and settlement and a refund of
/// something other than what was paid is a fee nobody agreed to.
/// `uint88` covers 309 million ether and packs the struct into one slot.
uint88 amount;
/// @dev Paid out or forfeited. Set before the transfer.
bool settled;
}
/// @notice The bond posted with each intent, if any.
mapping(bytes32 leaf => Bond) public bondOf;
/// @notice What `post` requires. Zero disables the bond entirely.
uint256 public bondWei;
/// @notice Where a forfeited bond goes.
/// @dev Zero means BURN — the value stays in this contract and nothing can
/// move it. That is the safe default rather than an oversight: a forfeit
/// destination is a revenue stream, and one set by accident is worse than
/// one that does not exist. Arming a bond without naming a destination is
/// refused, so this can never be reached by forgetting.
address public bondForfeitTo;
/// @notice Native this contract may not spend: every bond it still owes
/// out, plus every bond it has burned in place.
///
/// @dev `bondOf` is per-leaf and a mapping cannot be iterated, so the total
/// is maintained incrementally — the same rule `FinalPhiSupply.totalAllocated`
/// follows, and for the same reason: a liability that can only be totalled
/// by an off-chain sweep is not a liability the contract can defend. It is
/// what `_sweepReserved` fences, so a rescue of a stray asset can never
/// reach a poster's refund.
///
/// A bond leaves this total when it is refunded (`claimBond`) or when it is
/// forfeited TO A DESTINATION (`forfeitBond` with `bondForfeitTo` set): both
/// send the wei out, so the obligation ends with the transfer. A forfeit to
/// a zero destination does NOT leave it. That case burns the value in place
/// — deliberately, which is why arming a bond without a destination is
/// refused — and letting the burn fall out of the total would quietly turn
/// it into sweepable revenue, which is the opposite of what it was.
uint256 public reservedBondWei;
/// @notice The bond rate, or its destination, changed.
event BondPolicySet(uint256 bondWei, address forfeitTo);
/// @notice A bond was posted alongside an intent.
event BondPosted(bytes32 indexed leaf, address indexed payer, uint256 amount);
/// @notice A bond was returned after the intent was anchored.
event BondRefunded(bytes32 indexed leaf, address indexed payer, uint256 amount);
/// @notice A bond was forfeited: the intent expired without being anchored.
event BondForfeited(bytes32 indexed leaf, address indexed payer, uint256 amount);
/// @notice Thrown when a posting's bond does not match what the policy requires.
/// @param required The bond the policy demands.
/// @param supplied The bond offered.
error BondMismatch(uint256 required, uint256 supplied);
/// @notice Thrown when a bond operation names an intent that posted none.
/// @param leaf The intent.
error NoBond(bytes32 leaf);
/// @notice Thrown when a bond that has already been refunded or forfeited is settled again.
/// @param leaf The intent.
error BondAlreadySettled(bytes32 leaf);
/// @notice Thrown when a bond is refunded for an intent that did not earn it back.
/// @dev The bond is what makes posting cost something: refunding one that was not honoured would make
/// posting free again and the deterrent nominal.
/// @param leaf The intent.
error BondNotRefundable(bytes32 leaf);
/// @notice Thrown when a bond is forfeited before the intent's deadline has passed.
/// @dev Forfeiting early would take a bond from a poster who still had time to honour the intent.
/// @param leaf The intent.
/// @param deadline The deadline that has not yet passed.
error BondNotForfeitable(bytes32 leaf, uint64 deadline);
/// @notice Thrown when paying out a bond fails.
/// @param to The intended recipient.
/// @param amount The amount that failed to transfer.
error BondTransferFailed(address to, uint256 amount);
/// @notice Thrown when a bond policy sets a bond without naming where a forfeit goes.
/// @dev A forfeitable bond with nowhere to go would be burned by accident rather than by decision.
error BondNeedsAForfeitDestination();
/// @notice The one contract allowed to consume. Set once.
address public consumer;
/// @notice Discovery only. The envelope itself is in state — read it with
/// `envelopeOf`, which needs no `getLogs` range.
event IntentPosted(
bytes32 indexed leaf,
bytes32 indexed targetChainRef,
uint64 executeNotBefore,
uint64 deadline,
uint8 flags,
uint256 headerBytes,
uint256 ciphertextBytes
);
/// @notice The user read the posted intent back and approved it. Carries
/// the executor section's size — the bytes that let the executor
/// decrypt from here on.
event IntentApproved(bytes32 indexed leaf, uint256 executorSectionBytes);
/// @notice The approval key revoked the intent. Terminal.
event IntentCancelled(bytes32 indexed leaf);
/// @notice Consumed by an anchoring append.
event IntentConsumed(bytes32 indexed leaf, address indexed by);
/// @notice The single consumer permitted to mark intents consumed was pinned.
/// @param consumer The consumer.
event ConsumerSet(address indexed consumer);
/// @notice A target chain's schedule lead was configured.
/// @notice Thrown when an intent header is shorter than the fields it must contain.
/// @dev Checked before any offset is read, so a short header is refused rather than parsed against whatever
/// follows it in calldata.
/// @param length The length supplied.
error HeaderTooShort(uint256 length);
/// @notice Thrown when a header declares a version this log does not parse.
/// @dev Asserted rather than inferred: reading one layout's bytes under another's field names produces a
/// well-formed intent that means something else entirely.
/// @param version The version declared.
error UnsupportedHeaderVersion(uint8 version);
/// @notice Thrown when an intent is posted or acted on after its deadline.
/// @dev Times here are MILLISECONDS, as everywhere on this chain.
/// @param deadline The intent's deadline.
/// @param nowMs The current time.
error DeadlinePassed(uint64 deadline, uint64 nowMs);
/// @notice Thrown when an intent's deadline is further out than the log permits.
/// @dev Bounding it stops an intent standing open indefinitely as a claim nothing will ever clear.
/// @param deadline The deadline supplied.
/// @param limit The furthest the log allows.
error DeadlineTooFar(uint64 deadline, uint64 limit);
/// @notice Thrown when the zero leaf is offered as an intent identifier.
error ZeroLeaf();
/// @notice Thrown when an intent leaf that is already posted is posted again.
/// @param leaf The intent.
error AlreadyPosted(bytes32 leaf);
/// @notice Thrown when an intent that was never posted is acted on.
/// @param leaf The intent.
error NotPosted(bytes32 leaf);
/// @notice Thrown when an intent that is already consumed is consumed again.
/// @dev Consumption is terminal and one-shot, which is what stops one approval funding two executions.
/// @param leaf The intent.
/// @param at When it was consumed.
error AlreadyConsumed(bytes32 leaf, uint64 at);
/// @notice Thrown when an expired intent is consumed.
/// @param leaf The intent.
/// @param deadline The deadline that passed.
error Expired(bytes32 leaf, uint64 deadline);
/// @notice Header flag bits beyond the ones this version defines.
error UnsupportedFlags(uint8 flags);
/// @notice An AUTO_APPROVE header must commit to no approval key.
error AutoApproveTakesNoCommitment(bytes32 approvalKeyCommit);
/// @notice An approval-gated header must commit to one.
error ApprovalKeyCommitRequired();
/// @notice `executeNotBefore` sits beyond the scheduling horizon.
error ScheduleTooFar(uint64 executeNotBefore, uint64 limit);
/// @notice The presented key does not hash to the header's commitment.
error WrongApprovalKey(bytes32 expected, bytes32 got);
/// @notice The signature did not verify under the committed key.
error ApprovalSignatureInvalid(bytes32 leaf);
/// @notice Thrown when an intent that is already approved is approved again.
/// @param leaf The intent.
/// @param at When it was approved.
error AlreadyApproved(bytes32 leaf, uint64 at);
/// @notice AUTO_APPROVE intents commit to no key: nothing to approve or
/// cancel per-intent. Their veto is the account-wide freeze.
error NoApprovalKey(bytes32 leaf);
/// @notice Thrown when a cancelled intent is approved or consumed.
/// @param leaf The intent.
/// @param at When it was cancelled.
error IntentIsCancelled(bytes32 leaf, uint64 at);
/// @notice `executeNotBefore` has not arrived. Scheduling is a chain rule.
error TooEarly(bytes32 leaf, uint64 executeNotBefore, uint64 nowMs);
/// @notice Neither approved nor AUTO_APPROVE: the user has not read it back.
error NotApproved(bytes32 leaf);
/// @notice Thrown when consumption is attempted by anything but the pinned consumer.
/// @param caller The rejected caller.
error NotConsumer(address caller);
/// @notice Thrown when consumption is attempted before a consumer is pinned.
error ConsumerUnset();
/// @notice Thrown when the consumer is pinned a second time.
/// @dev Write-once: a rotatable consumer would let whoever could move it consume every standing intent.
/// @param current The consumer already pinned.
error ConsumerAlreadySet(address current);
/// @notice Thrown when the zero address is offered as the consumer.
error ZeroConsumer();
/// @notice Thrown when a caller holds none of the authorities the entrypoint accepts.
/// @param caller The rejected caller.
error NotAuthorized(address caller);
/**
* @dev No precompile of its own to call — this contract verifies no
* signature and reads no PQ key, it hashes and compares. The probe is
* still here because the claim "these deploy to Final Chain and nowhere
* else" should be enforced rather than documented, and a posting log on
* an execution chain would be a place intents could be posted that no
* anchor will ever read.
*/
constructor(FinalIdentityRegistry registry_, FinalStateTrees trees_) {
FinalChainPrecompiles.assertAvailable();
registry = registry_;
trees = trees_;
}
/// @notice A fresh log took over the previous log's sequence.
event SequenceSeeded(uint64 postSeq);
/// @notice The sequence can be seeded only into a log that holds nothing.
error NotFresh();
/**
* @notice Take over the previous log's `postSeq`, so every walker's cursor
* (`postSeq` is the count; the fleet walks it, never a `getLogs`
* range) stays ahead of nothing and behind everything new. Slots
* below the seed belong to the previous log. A redeploy does NOT
* wipe. Configuration authority; only while empty.
*/
function seedSequence(
uint64 postSeq_,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireConfigurationAuthority(
ACTION_SEED_SEQUENCE, keccak256(abi.encode(postSeq_)), anchorBlock, approvals
);
if (postSeq != 0) revert NotFresh();
postSeq = postSeq_;
emit SequenceSeeded(postSeq_);
}
/**
* @dev The configuration gate: the registry's bootstrap admin alone while
* its window is open, the sealed `ROLE_REGISTRAR` quorum afterwards — the
* same window and quorum the registry and the trees use. `approvals` is
* empty during bootstrap.
*/
function _requireConfigurationAuthority(
bytes32 actionDomain,
bytes32 payloadDigest,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) private {
if (!registry.bootstrapSealed() && msg.sender == registry.bootstrapAdmin()) return;
registry.requireRegistrarQuorum(actionDomain, payloadDigest, anchorBlock, approvals);
}
/**
* @notice Name the contract allowed to consume postings.
*
* @dev One-way and one-shot, like `FinalStateTrees.treeWriter`. Deployment
* is circular — the bundle log needs this address in its constructor —
* so this is set afterwards, and it can never be moved: a consumer that
* could be repointed would be a consumer that could be replaced with
* one that does not check.
*
* Authorized, and it has to be. Left open it would be a front-run away
* from permanent: an attacker naming their own contract first would
* brick the PQ lane with no recovery, because one-shot cuts both ways.
*/
function setConsumer(
address newConsumer,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireConfigurationAuthority(
ACTION_SET_CONSUMER, keccak256(abi.encode(newConsumer)), anchorBlock, approvals
);
if (consumer != address(0)) revert ConsumerAlreadySet(consumer);
if (newConsumer == address(0)) revert ZeroConsumer();
consumer = newConsumer;
emit ConsumerSet(newConsumer);
}
/// @notice The lead a scheduled posting for `targetChainRef` gets: the
/// config-branch row when one exists (explicit zero included),
/// else `DEFAULT_SCHEDULE_LEAD_MS`. Capped at the schedule horizon:
/// a longer lead would make every scheduled posting consumable at
/// post time. The fleet reads this so the watch and the contract
/// agree on when an attempt may begin.
function scheduleLeadMsOf(bytes32 targetChainRef) public view returns (uint64) {
(bytes32 value, bool present) =
trees.configValue(TREE_INTENTS_ID, trees.configKey(CONFIG_SCHEDULE_LEAD_MS, targetChainRef));
if (!present) return DEFAULT_SCHEDULE_LEAD_MS;
uint256 lead = uint256(value);
return lead > MAX_SCHEDULE_HORIZON ? MAX_SCHEDULE_HORIZON : uint64(lead);
}
/**
* @notice Post an intent. Permissionless.
*
* @dev Permissionless on purpose. Gating posting on an identity would
* reintroduce exactly the attribution the encryption removes, so what
* bounds a spammer is the BOND rather than a quota: `msg.value` must
* equal `bondWei`, and it comes back only if the intent is anchored.
*
* While `bondWei` is zero — the shipped state — this is what it has
* always been, and `msg.value` must then be zero too. Accepting a
* payment the contract has no rule for would be accepting value it
* cannot refund.
*
* @param header Canonical envelope header. Parsed, never stored.
* @param ciphertext The sealed body. Emitted, never stored, never read.
* @return leaf The intent leaf this posting is keyed on.
*/
function post(bytes calldata header, bytes calldata ciphertext)
external
payable
returns (bytes32 leaf)
{
if (header.length < HEADER_MIN_BYTES) revert HeaderTooShort(header.length);
uint8 version = uint8(header[0]);
if (version < HEADER_VERSION || version > HEADER_VERSION_MAX) {
revert UnsupportedHeaderVersion(version);
}
uint8 flags = uint8(header[OFF_FLAGS]);
if (flags & ~FLAG_AUTO_APPROVE != 0) revert UnsupportedFlags(flags);
bytes32 targetChainRef = bytes32(header[OFF_TARGET_CHAIN_REF:OFF_TARGET_CHAIN_REF + 32]);
uint64 executeNotBefore =
uint64(bytes8(header[OFF_EXECUTE_NOT_BEFORE:OFF_EXECUTE_NOT_BEFORE + 8]));
uint64 deadline = uint64(bytes8(header[OFF_DEADLINE:OFF_DEADLINE + 8]));
bytes32 bodyCommitment = bytes32(header[OFF_BODY_COMMITMENT:OFF_BODY_COMMITMENT + 32]);
leaf = bytes32(header[OFF_INTENT_LEAF:OFF_INTENT_LEAF + 32]);
bytes32 approvalKeyCommit =
bytes32(header[OFF_APPROVAL_KEY_COMMIT:OFF_APPROVAL_KEY_COMMIT + 32]);
// The commitment and the flag are one decision stated twice, so the two
// must agree: an auto intent with a commitment would look cancellable
// and not be gated, and a gated one without a commitment could never be
// approved by anyone — dead on arrival, wearing a live intent's shape.
bool auto_ = flags & FLAG_AUTO_APPROVE != 0;
if (auto_ && approvalKeyCommit != bytes32(0)) {
revert AutoApproveTakesNoCommitment(approvalKeyCommit);
}
if (!auto_ && approvalKeyCommit == bytes32(0)) revert ApprovalKeyCommitRequired();
if (leaf == bytes32(0)) revert ZeroLeaf();
if (postedOf[leaf].postedAt != 0) revert AlreadyPosted(leaf);
// Scheduling is a contract rule. An immediate intent gets the window
// from now; a scheduled one gets it from its own start, and the start
// itself is bounded by the horizon — chosen at signing, because the
// deadline is inside the signed intent and cannot be extended after.
uint64 nowMs = FinalChainTime.nowMs();
if (deadline <= nowMs) revert DeadlinePassed(deadline, nowMs);
if (executeNotBefore == 0) {
uint64 limit = nowMs + EXECUTION_WINDOW;
if (deadline > limit) revert DeadlineTooFar(deadline, limit);
} else {
uint64 horizon = nowMs + MAX_SCHEDULE_HORIZON;
if (executeNotBefore > horizon) revert ScheduleTooFar(executeNotBefore, horizon);
uint64 limit = executeNotBefore + EXECUTION_WINDOW;
if (deadline > limit) revert DeadlineTooFar(deadline, limit);
}
// The bond scales with lifetime. A month-long posting occupies state
// and attention a 48-hour one does not, and a flat bond makes
// long-lived spam the cheap kind. Ceiling division, so a single extra
// millisecond of a new window costs a whole unit.
uint256 required = bondWei;
if (required != 0) {
required = required
* ((uint256(deadline) - nowMs + EXECUTION_WINDOW - 1) / EXECUTION_WINDOW);
}
if (required > type(uint88).max) revert BondMismatch(type(uint88).max, required);
if (msg.value != required) revert BondMismatch(required, msg.value);
uint64 seq = postSeq;
postSeq = seq + 1;
leafAt[seq] = leaf;
postedOf[leaf] = Posted({
postedAt: nowMs,
executeNotBefore: executeNotBefore,
deadline: deadline,
consumedAt: 0,
bodyCommitment: bodyCommitment,
approvalKeyCommit: approvalKeyCommit,
targetChainRef: targetChainRef,
approvedAt: 0,
cancelledAt: 0,
seq: seq,
flags: flags
});
_envelopeOf[leaf] = Envelope({header: header, ciphertext: ciphertext, executorSection: ""});
if (required != 0) {
bondOf[leaf] = Bond({payer: msg.sender, amount: uint88(required), settled: false});
reservedBondWei += required;
emit BondPosted(leaf, msg.sender, required);
}
_writeStatus(leaf, postedOf[leaf], STATUS_POSTED);
emit IntentPosted(
leaf, targetChainRef, executeNotBefore, deadline, flags, header.length, ciphertext.length
);
}
/**
* @notice Set the bond rate and where a forfeit goes.
*
* @dev Same gate as `setConsumer`, and unlike it this is NOT one-shot: a
* bond is a price and a price that could never move would be a parameter
* chosen once, before the traffic it is meant to bound existed.
*
* Arming a non-zero bond without a forfeit destination is refused. Zero
* means burn, which is a real choice — but it has to be made rather than
* arrived at by leaving a field unset, because the difference is an
* accumulating balance nobody can ever move.
*
* Changing the rate does not touch bonds already posted. Each stores what
* was actually paid, so a rate rise cannot retroactively underpay a refund
* and a cut cannot leave one over-funded.
*/
function setBondPolicy(
uint256 newBondWei,
address forfeitTo,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireConfigurationAuthority(
ACTION_SET_BOND_POLICY, keccak256(abi.encode(newBondWei, forfeitTo)), anchorBlock, approvals
);
if (newBondWei != 0 && forfeitTo == address(0)) {
// Only when ARMING. Setting the rate back to zero with no
// destination is disarming, which needs no destination.
revert BondNeedsAForfeitDestination();
}
if (newBondWei > type(uint88).max) revert BondMismatch(type(uint88).max, newBondWei);
bondWei = newBondWei;
bondForfeitTo = forfeitTo;
emit BondPolicySet(newBondWei, forfeitTo);
}
/**
* @notice Return a bond whose intent was anchored.
*
* @dev Permissionless to CALL and fixed in destination: the money goes to
* the recorded payer whoever asks. That is what lets a relayer sweep on a
* user's behalf without being able to redirect anything.
*
* A pull rather than a push inside `consume`. `consume` runs in the
* anchoring append, and a refund there would put an arbitrary payer's
* `receive` on the path of every bundle — one contract that reverts, or
* burns the gas, and the anchor fails for reasons that have nothing to do
* with the bundle.
*
* `consumedAt != 0` is the whole test. Consumption means `FinalBundleLog`
* folded this leaf into an anchored bundle, which is exactly "valid
* execution" — there is no later outcome for the chain to wait on, because
* from here the execution chains authorize against the anchor.
*/
function claimBond(bytes32 leaf) external {
Bond storage b = bondOf[leaf];
if (b.payer == address(0)) revert NoBond(leaf);
if (b.settled) revert BondAlreadySettled(leaf);
if (postedOf[leaf].consumedAt == 0) revert BondNotRefundable(leaf);
b.settled = true;
uint256 amount = b.amount;
address payer = b.payer;
reservedBondWei -= amount;
emit BondRefunded(leaf, payer, amount);
_send(payer, amount);
}
/**
* @notice Forfeit the bond on an intent that expired without being anchored.
*
* @dev Permissionless, and gated on the DEADLINE rather than on a judgement.
* An intent past its deadline can never be consumed — `consume` refuses one
* — so "expired and unconsumed" is a terminal, objective state, and anyone
* may say so.
*
* That is the half of the bond that actually bounds spam. A refund on
* success only makes an honest posting free; the cost of a vertex that goes
* nowhere is what a spammer pays.
*/
function forfeitBond(bytes32 leaf) external {
Bond storage b = bondOf[leaf];
if (b.payer == address(0)) revert NoBond(leaf);
if (b.settled) revert BondAlreadySettled(leaf);
Posted storage p = postedOf[leaf];
if (p.consumedAt != 0) revert BondNotForfeitable(leaf, p.deadline);
if (FinalChainTime.nowMs() <= p.deadline) revert BondNotForfeitable(leaf, p.deadline);
b.settled = true;
uint256 amount = b.amount;
address to = bondForfeitTo;
emit BondForfeited(leaf, b.payer, amount);
// A zero destination BURNS: the value stays here and nothing can move
// it. Deliberate, and the reason `setBondPolicy` refuses to arm a bond
// without a destination unless somebody chose this one. The reserve
// follows that: it drops only when the wei actually leaves, so a burn
// stays fenced and the sweep cannot undo it.
if (to != address(0)) {
reservedBondWei -= amount;
_send(to, amount);
}
}
/// @dev Checks-effects-interactions is done by the caller — `settled` is set
/// before this runs — so a reentrant call finds the bond already spent.
///
/// Full gas rather than a stipend, because a payer may legitimately be a
/// contract. The consequence to accept: a payer whose `receive` reverts
/// cannot be refunded and the bond is stuck. That is their own contract's
/// behaviour, and the alternative — swallowing the failure — would mark the
/// bond settled while the money stayed here.
function _send(address to, uint256 amount) private {
(bool ok,) = to.call{value: amount}("");
if (!ok) revert BondTransferFailed(to, amount);
}
/**
* @notice Approve a posted intent: the read-back that authorizes execution.
*
* @dev Anyone may SUBMIT this — the authority is the signature and the
* sender only pays gas, the same standing the guardian lanes give
* their relay. The key arrives in calldata and proves something only
* because it is checked against the commitment the header made at
* posting: storage-anchored evidence, exactly the rule `FinalPqQuorum`
* states for quorum keys.
*
* The digest binds this chain, this log, the leaf AND the executor
* section, so an approval cannot be replayed here or elsewhere, and
* the section it delivered cannot be swapped for another under the
* same signature.
*
* @param publicKey The per-intent ML-DSA-87 public key (2592 B).
* @param signature Over the 32-byte approval digest, verbatim (4627 B).
* @param executorSection The content key and the account's KEM public
* keys, sealed to the executor set. Stored beside the envelope;
* this contract never parses it.
*/
function approve(
bytes32 leaf,
bytes calldata publicKey,
bytes calldata signature,
bytes calldata executorSection
) external {
Posted storage p = _requireActionable(leaf);
if (p.approvedAt != 0) revert AlreadyApproved(leaf, p.approvedAt);
uint64 nowMs = FinalChainTime.nowMs();
if (nowMs > p.deadline) revert Expired(leaf, p.deadline);
bytes32 digest = keccak256(
abi.encode(
DOMAIN_INTENT_APPROVE, block.chainid, address(this), leaf, keccak256(executorSection)
)
);
_requireApprovalKey(p, publicKey, signature, digest, leaf);
p.approvedAt = nowMs;
_envelopeOf[leaf].executorSection = executorSection;
_writeStatus(leaf, p, STATUS_APPROVED);
emit IntentApproved(leaf, executorSection.length);
}
/**
* @notice Revoke a posted intent. Terminal, and allowed AFTER approval:
* a user may change their mind at any point before execution.
*
* @dev No deadline check — cancelling an expired intent is harmless and
* refusing it would fail a retry for nothing. Only consumption closes
* the door, because consumption is execution.
*/
function cancel(bytes32 leaf, bytes calldata publicKey, bytes calldata signature) external {
Posted storage p = _requireActionable(leaf);
bytes32 digest =
keccak256(abi.encode(DOMAIN_INTENT_CANCEL, block.chainid, address(this), leaf));
_requireApprovalKey(p, publicKey, signature, digest, leaf);
p.cancelledAt = FinalChainTime.nowMs();
_writeStatus(leaf, p, STATUS_CANCELLED);
emit IntentCancelled(leaf);
}
/// @dev Posted, not consumed, not cancelled — the states in which the
/// approval key still has anything to say.
function _requireActionable(bytes32 leaf) private view returns (Posted storage p) {
p = postedOf[leaf];
if (p.postedAt == 0) revert NotPosted(leaf);
if (p.consumedAt != 0) revert AlreadyConsumed(leaf, p.consumedAt);
if (p.cancelledAt != 0) revert IntentIsCancelled(leaf, p.cancelledAt);
}
/// @dev The committed key, and a valid ML-DSA-87 signature under it over
/// the 32-byte digest verbatim — the same convention every quorum approval
/// follows. An AUTO_APPROVE posting committed to nothing and has nothing
/// to approve or cancel; its veto is the account-wide freeze.
function _requireApprovalKey(
Posted storage p,
bytes calldata publicKey,
bytes calldata signature,
bytes32 digest,
bytes32 leaf
) private view {
bytes32 commit = p.approvalKeyCommit;
if (commit == bytes32(0)) revert NoApprovalKey(leaf);
bytes32 got = keccak256(publicKey);
if (got != commit) revert WrongApprovalKey(commit, got);
if (!FinalChainPrecompiles.verifyMlDsa87(publicKey, abi.encodePacked(digest), signature)) {
revert ApprovalSignatureInvalid(leaf);
}
}
// ------------------------------------------------------ tree-7 mirror
/// @notice The tree-7 key for posting sequence `seq` — a RING, so slots
/// recycle at `INTENT_SLOT_RING` and the tree can never fill.
/// @dev Mirrored by the backend byte for byte; pinned cross-repo.
function intentSlotKey(uint64 seq) public pure returns (bytes32) {
return keccak256(
abi.encodePacked(DOMAIN_INTENT_KEY, bytes32(uint256(seq % INTENT_SLOT_RING)))
);
}
/// @notice The tree-7 status leaf. Everything in it is public log state —
/// nothing account-linked, so the tree adds searchability without
/// touching unlinkability. Expiry is derived from `deadline` by the
/// reader, never written.
function intentStatusLeaf(
bytes32 intentLeaf,
uint8 status,
uint64 postedAt,
uint64 executeNotBefore,
uint64 deadline,
bytes32 targetChainRef,
bytes32 bodyCommitment,
uint64 seq
) public pure returns (bytes32) {
return keccak256(
bytes.concat(
DOMAIN_INTENT_STATUS_LEAF,
abi.encode(
intentLeaf,
status,
postedAt,
executeNotBefore,
deadline,
targetChainRef,
bodyCommitment,
seq
)
)
);
}
/// @dev One transition, one write. The log is `treeWriter[7]`, and the
/// tree-1 argument applies verbatim: everything this mirrors was already
/// verified here, so no quorum belongs on top.
function _writeStatus(bytes32 leaf, Posted storage p, uint8 status) private {
bytes32[] memory keys = new bytes32[](1);
bytes32[] memory statusLeaves = new bytes32[](1);
keys[0] = intentSlotKey(p.seq);
statusLeaves[0] = intentStatusLeaf(
leaf,
status,
p.postedAt,
p.executeNotBefore,
p.deadline,
p.targetChainRef,
p.bodyCommitment,
p.seq
);
trees.setLeavesAsWriter(TREE_INTENTS_ID, BRANCH_MAIN_ID, keys, statusLeaves);
}
/**
* @notice Consume a posted intent as part of an anchoring append.
*
* @dev Called by `FinalBundleLog` in the same transaction as the append, so
* there is no window in which a bundle is anchored and its intents are
* not yet spent.
*
* Consumption is permanent and is the replay gate. The execution chain
* keeps its own consumed-seqId set, which covers a bundle being
* re-executed; this covers an intent being re-anchored into a second
* bundle, which that set does not see.
*/
function consume(bytes32 leaf) external {
// Checked before the comparison, not folded into it. An unset consumer
// is `address(0)`, and `msg.sender != consumer` would then be FALSE for
// a caller of `address(0)` — so an unwired log would consume for the one
// caller nobody can be, which is the kind of "unreachable" that stops
// being unreachable the moment something else changes.
address c = consumer;
if (c == address(0)) revert ConsumerUnset();
if (msg.sender != c) revert NotConsumer(msg.sender);
Posted storage p = postedOf[leaf];
if (p.postedAt == 0) revert NotPosted(leaf);
if (p.consumedAt != 0) revert AlreadyConsumed(leaf, p.consumedAt);
if (p.cancelledAt != 0) revert IntentIsCancelled(leaf, p.cancelledAt);
uint64 nowMs = FinalChainTime.nowMs();
if (nowMs > p.deadline) revert Expired(leaf, p.deadline);
// Scheduling is enforced HERE, which is what makes the funding and fee
// re-checks execution-time checks for free: admission cannot happen
// before the moment the intent named — less the lead, so the wrapper
// that follows admission can land AT that moment rather than minutes
// after it (`SCHEDULE_LEAD_MS`).
if (nowMs + _scheduleLeadMs(p) < p.executeNotBefore) {
revert TooEarly(leaf, p.executeNotBefore, nowMs);
}
// The read-back gate. Neither approved nor auto means the user has not
// seen on chain what is about to execute.
if (p.approvedAt == 0 && p.flags & FLAG_AUTO_APPROVE == 0) revert NotApproved(leaf);
p.consumedAt = nowMs;
_writeStatus(leaf, p, STATUS_CONSUMED);
emit IntentConsumed(leaf, msg.sender);
}
/// @notice The stored envelope. One `eth_call`, no range, any age.
///
/// @dev A getter rather than a public mapping so the three parts come back
/// in one call — a caller pairing a header from one read with a
/// ciphertext from another would be pairing across a posting that
/// landed between them.
function envelopeOf(bytes32 leaf)
external
view
returns (bytes memory header, bytes memory ciphertext, bytes memory executorSection)
{
Envelope storage e = _envelopeOf[leaf];
return (e.header, e.ciphertext, e.executorSection);
}
/// @notice Is `leaf` posted, unspent, uncancelled and unexpired right now?
function isOpen(bytes32 leaf) external view returns (bool) {
Posted storage p = postedOf[leaf];
return p.postedAt != 0 && p.consumedAt == 0 && p.cancelledAt == 0
&& FinalChainTime.nowMs() <= p.deadline;
}
/// @notice Would `consume` accept `leaf` right now? Open, due, and either
/// approved or AUTO_APPROVE — the work-queue predicate, so a solver
/// asks the same question the contract answers.
function isConsumable(bytes32 leaf) external view returns (bool) {
Posted storage p = postedOf[leaf];
uint64 nowMs = FinalChainTime.nowMs();
return p.postedAt != 0 && p.consumedAt == 0 && p.cancelledAt == 0 && nowMs <= p.deadline
&& nowMs + _scheduleLeadMs(p) >= p.executeNotBefore
&& (p.approvedAt != 0 || p.flags & FLAG_AUTO_APPROVE != 0);
}
/// @dev The lead `consume` grants a posting: its target chain's
/// (`scheduleLeadMsOf`) for a scheduled one, nothing for an immediate
/// one (there is no moment to lead).
function _scheduleLeadMs(Posted storage p) private view returns (uint64) {
return p.executeNotBefore == 0 ? 0 : scheduleLeadMsOf(p.targetChainRef);
}
// ------------------------------------------------------------------ sweep
/// @dev This contract's configuration gate reads the membership registry it
/// was constructed against, so the sweep authority reads the same one.
function _sweepRegistry() internal view override returns (FinalIdentityRegistry) {
return registry;
}
/// @dev The recorded forfeit destination, and the proven authority that
/// called. `bondForfeitTo` is the one address this contract already names
/// as somewhere its native value legitimately goes, so a rescue pays it
/// rather than inventing a second one. Zero while no bond is armed — the
/// shipped state — and `FinalSweep` refuses a zero destination, so the pair
/// collapses to the caller until a forfeit destination exists.
function _sweepDestinations() internal view override returns (address, address) {
return (bondForfeitTo, msg.sender);
}
/**
* @dev The outstanding bonds are the liability, and the whole of it.
*
* A posted bond is native this contract is holding FOR the poster: refunded
* by `claimBond` once the intent is anchored, forfeited by `forfeitBond`
* once its deadline passes without anchoring. Either way it is somebody
* else's wei until it settles, and a sweep that could take it would let a
* registrar collect the spam deposit of every intent still in flight.
* `reservedBondWei` also keeps holding the bonds forfeited to a zero
* destination, which are burned in place and must stay burned.
*
* Nothing else here is owed: intents are records, not custody, and this
* contract has no other payable entrypoint — so a foreign token, an NFT or
* native beyond the bond total is stray and sweepable in full.
*/
function _sweepReserved(SweepKind kind, address, uint256) internal view override returns (uint256) {
return kind == SweepKind.Native ? reservedBondWei : 0;
}
}
contracts/finalchain/FinalPlaneSweep.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may inherit this mixin from a contract deployed as
// part of a Final DeFi Protocol state plane, and may operate the asset-rescue
// surface it completes.
// 2. Integrators, indexers and operators may call the resulting rescue surface
// where the state plane's own configuration authority permits it, and may
// read the authority and destination answers it gives.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this mixin or a competing state-plane rescue
// authority without permission prior to the Change Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
import {FinalSweep} from "../utils/FinalSweep.sol";
import {FinalIdentityRegistry} from "./FinalIdentityRegistry.sol";
/**
* @title Final Plane Sweep
* @notice The authority and destination halves of the shared asset-rescue surface, answered once for every
* contract of the protocol's own state plane.
* @dev `FinalSweep` gives every contract that can end up holding a stray asset one rescue surface and leaves two
* questions for the inheritor: who may call it, and where the value may go. Every contract on this state
* plane answers both the same way — the registry's bootstrap admin alone while that window is open, and the
* sealed registrar authority afterwards — and stating that once per contract would be one chance per
* contract to state it differently. An inheritor of this mixin answers a single question instead: which
* registry is mine.
*
* **The authority is the plane's own configuration gate, narrowed to what a fixed signature can carry.**
* The sealed half of that gate is a K-of-N over the registrar role, and its approvals arrive in CALLDATA.
* The rescue entrypoint's signature is shared across every contract on the plane and cannot grow a
* per-contract quorum argument, so what survives into a no-argument `internal view` is MEMBERSHIP: the
* bootstrap admin while the window is open, and afterwards any account the registry currently attests as a
* live registrar.
*
* That is a narrowing — one registrar rather than K of them — and it is deliberate rather than overlooked.
* Two other gates make it safe, and a registrar can widen neither:
*
* - a rescue moves SURPLUS only. Every contract that owes something declares the debt as a reservation,
* and no key reaches behind that line: an intent log's bonds, a billing plane's prepaid credit and a gas
* well's entire float are all unreachable by this surface however it is called.
* - the destination is not the caller's to invent.
*
* A registrar already configures tree writers, thresholds and consumers. An account that can decide who may
* write the account tree is not meaningfully restrained from moving a stray token, so demanding a quorum
* ceremony for the rescue lane would buy nothing and would instead guarantee the lane is never used when it
* is needed. No new role and no new authority pointer is introduced here: the registrar role is the
* registry's own, and membership in it moves in the registry rather than in any contract that reads it.
*
* **The destination is the authority that ordered the rescue.** This state plane has no treasury pointer,
* and adding one would be exactly the new authority this mixin is not allowed to invent — a per-contract
* treasury setter would need its own quorum action on every contract of the plane, to configure something
* the plane has never needed. So the two legitimate destinations are the two addresses already proven: the
* bootstrap admin, and the caller.
*
* The caller is not a free parameter. The rescue entrypoint proves the authority BEFORE it resolves
* destinations, so by the time this mixin is asked, the sender is already either the bootstrap admin or a
* live registrar. Every service on this chain is a Final Wallet with a registered identity and no EOA
* signing key, so the value lands on an account the chain itself attests to. What the gate rules out is the
* thing worth ruling out: a rescue paying an address the plane knows nothing about.
*
* Once the bootstrap window is sealed the admin address is zero, and the base contract refuses a zero
* destination, so the pair collapses to the caller alone — one legitimate destination, which is the case the
* base contract already handles.
*/
abstract contract FinalPlaneSweep is FinalSweep {
/// @notice The membership registry an inheriting contract's configuration gate reads.
/// @dev The one question this mixin leaves open, and the only line an inheritor has to supply. It exists
/// because some contracts of the plane hold the registry directly while others reach it through another
/// contract they already hold, and both must resolve to the SAME registry their configuration answers
/// to — a rescue authority read from a different source would be a second authority in disguise.
/// @return The registry whose bootstrap admin and registrar membership decide this contract's rescue
/// authority and destinations.
function _sweepRegistry() internal view virtual returns (FinalIdentityRegistry);
/// @notice The plane's configuration gate, in the caller-only form the shared rescue surface can express.
/// @dev Two accepting branches, checked in order: the bootstrap admin while the window is open, and any live
/// registrar once it is sealed. The bootstrap branch is guarded on the seal as well as on the address,
/// so it closes the moment the window does rather than depending on the admin field being cleared.
/// Membership is read live from the registry on every call, so revoking a registrar there revokes this
/// authority everywhere on the plane at once. Anything else reverts.
function _requireSweepAuthority() internal view virtual override {
FinalIdentityRegistry reg = _sweepRegistry();
if (!reg.bootstrapSealed() && msg.sender == reg.bootstrapAdmin()) return;
if (reg.hasRole(msg.sender, reg.ROLE_REGISTRAR())) return;
revert SweepUnauthorized(msg.sender);
}
/// @notice The two addresses a rescue on this plane may pay.
/// @dev The bootstrap admin, and the authority that called — which the base contract has already proven by
/// the time this is read, so the second is never an address of the caller's choosing. After the seal the
/// admin half is the zero address, which the base contract refuses as a destination, leaving the proven
/// caller as the single legitimate target.
/// @return The bootstrap admin, and the proven caller.
function _sweepDestinations() internal view virtual override returns (address, address) {
return (_sweepRegistry().bootstrapAdmin(), msg.sender);
}
}
contracts/finalchain/FinalPqQuorum.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may deploy and operate this quorum as part of a
// Final DeFi Protocol chain, and may inherit it to gate an action behind a
// post-quantum K-of-N.
// 2. Integrators, auditors, and node operators may read its membership and
// thresholds and independently re-verify any approval it recorded, as part
// of their integration with the Final DeFi Protocol.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this quorum or a competing identity or
// authorization plane derived from it without permission prior to the
// Change Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
import {FinalChainPrecompiles} from "./FinalChainPrecompiles.sol";
import {FinalIdentityRegistry} from "./FinalIdentityRegistry.sol";
/**
* @title FinalPqQuorum
* @notice K-of-N approval where the signatures are post-quantum and the chain
* is what checks them.
*
* @dev This library is the reason Final Chain exists in this design.
*
* `FinalBackend/src/pq/credential.js` carries a rule it had to enforce in code
* because nothing else could: **a surface whose signature is verified on chain
* cannot be PQ.** A co-signer approval reaching `FinalRootAuthority` is checked
* by ECDSA/ERC-1271 in Solidity, so a PQ co-signer would produce approvals the
* contract cannot read, and the quorum would stop reaching threshold with
* nothing in any log naming the cause. `PQ_SURFACE` and `assertBackendVerified`
* exist to keep anyone from crossing that line by accident.
*
* Here the line is gone. The precompiles verify ML-DSA-87 and
* SLH-DSA-SHAKE-256s natively, so a quorum can be PQ *and* on chain, and
* "the backend says these four signatures verified" becomes "these four
* signatures verify, and any node re-derives that independently".
*
* ## Three rules, each closing a specific hole
*
* 1. **Keys come from the registry, never from calldata.** A key passed as an
* argument proves nothing — anyone with a keypair can sign under it. This is
* the difference between a 4-of-5 quorum and a 1-of-1 held by whoever built
* the transaction.
*
* 2. **Signers strictly ascending.** One comparison per entry rejects duplicates
* outright, so a single member cannot supply four approvals and satisfy a
* threshold of four. The alternative — an O(n²) seen-check — is the same
* guarantee with more ways to get it wrong.
*
* 3. **The digest binds chain id and verifying contract.** Without both, an
* approval collected for one contract is replayable against another with the
* same payload shape, and an approval from the test chain is replayable on
* the production one. These co-signers hold one key across environments.
*
* ## Which algorithm
*
* The stack splits its keys by hardness assumption, not by convenience:
* ML-DSA-87 (lattice) signs transactions, SLH-DSA-SHAKE-256s (hash-based) signs
* identity. Two families, so one cryptanalytic result cannot take both.
*
* So an action inherits the class of what it authorizes. Advancing a state root
* is operational and high-cadence: transaction class. Registering or revoking
* an identity is the thing the access class exists for. `ALG_ANY` is available
* and should be used sparingly — accepting either means a break in one family
* takes the quorum.
*
* An action that authorizes EXECUTION takes both: the ML-DSA-87 approval and a
* `seal`, an SLH-DSA-SHAKE-256s signature over the same digest by the member's
* `activeSeal` key. Neither family alone can then move funds, and the seal key
* is its own slot — never the access key — so the process that seals cannot
* also rotate the identity it seals for.
*
* Every digest binds an `anchorBlock`: the block at which the members read
* tree 1 to decide who is in the round. Binding it means every approval in a
* round was made against ONE roster view, and the window in `require_` means a
* view older than `ANCHOR_WINDOW` blocks is refused rather than honoured.
*
* The practical cost is worth stating: an SLH-DSA signature is 29,792 bytes, so
* a 4-of-5 access-class quorum is ~119 KB of calldata. That is affordable here
* only because this is our own chain. Do not carry this pattern to a chain
* where it is not.
*/
library FinalPqQuorum {
/// @notice ML-DSA-87 — FIPS 204. Algorithm ids are the FIPS numbers: the
/// same ids `FinalCertificate` and the backend registry use, and the numbers
/// the precompile addresses end in (`0x0204`).
uint8 internal constant ALG_ML_DSA_87 = 4;
/// @notice SLH-DSA-SHAKE-256s — FIPS 205 (`0x0205`).
uint8 internal constant ALG_SLH_DSA_SHAKE_256S = 5;
/// @notice Either scheme is acceptable for this action.
uint8 internal constant ALG_ANY = 0;
/// @notice How far behind the chain head an approval's anchor may sit.
/// @dev Members evaluate roster membership against tree 1 AT the anchor
/// block. 600 blocks is ten minutes at the chain's one-second cadence —
/// generous against a round that takes seconds, and short enough that a
/// roster rotated away is refused rather than counted.
uint64 internal constant ANCHOR_WINDOW = 600;
/// @dev Domain separator for every quorum digest. Distinct from any
/// EIP-712 domain in the stack: these are not typed-data signatures and
/// must not be confusable with one.
bytes32 internal constant DOMAIN_PQ_QUORUM = keccak256("FINAL_CHAIN_PQ_QUORUM_v01");
/// @notice One member's approval.
struct Approval {
/// The member's account, which is also the key it is looked up by.
address signer;
/// `ALG_ML_DSA_87` or `ALG_SLH_DSA_SHAKE_256S`.
uint8 algorithm;
/// Over the 32-byte digest from `digest()`, verbatim. Both schemes
/// hash internally, so the digest is not re-hashed before signing.
bytes signature;
/// SLH-DSA-SHAKE-256s over the same digest, by the member's `activeSeal`
/// key. Required where the action authorizes execution; empty otherwise.
bytes seal;
}
/// @notice Thrown when fewer valid approvals were supplied than the action requires.
/// @param valid Approvals that verified.
/// @param required Approvals the action demands.
error ThresholdNotMet(uint256 valid, uint256 required);
/// @notice Thrown when approvals are not in strictly ascending signer order.
/// @dev Ascending order is what makes duplicate detection a single comparison instead of a quadratic scan,
/// so it is the rule that stops one signer being counted twice toward a threshold.
/// @param previous The preceding signer.
/// @param next The signer that failed to exceed it.
error SignersNotAscending(address previous, address next);
/// @notice Thrown when an approving signer does not hold the role this action is gated on.
/// @param signer The approving signer.
/// @param roleMask The role the action requires.
error SignerLacksRole(address signer, uint256 roleMask);
/// @notice Thrown when an approval is signed under an algorithm this action does not accept.
/// @param signer The approving signer.
/// @param got The algorithm the approval declared.
/// @param required The algorithm the action demands.
error WrongAlgorithm(address signer, uint8 got, uint8 required);
/// @notice Thrown when an approval's signature fails verification in the precompile.
/// @param signer The approving signer.
/// @param algorithm The algorithm it was verified under.
error BadSignature(address signer, uint8 algorithm);
/// @notice Thrown when an approval's access seal fails verification.
/// @param signer The approving signer.
error BadSeal(address signer);
/// @notice Thrown when an approval anchors to a block this chain has not reached.
/// @param anchorBlock The block the approval anchored to.
/// @param blockNumber The current block.
error AnchorAhead(uint64 anchorBlock, uint256 blockNumber);
/// @notice Thrown when an approval's anchor is older than the accepted window.
/// @dev Bounding the window is what stops an approval collected once being replayed indefinitely later.
/// @param anchorBlock The block the approval anchored to.
/// @param blockNumber The current block.
error AnchorStale(uint64 anchorBlock, uint256 blockNumber);
/// @notice Thrown when an action is gated on a threshold of zero.
/// @dev Refused rather than treated as "no approvals needed": a zero threshold is always a
/// misconfiguration, and reading it as permissive would silently remove the quorum.
error ThresholdIsZero();
/**
* @notice The message every member of this quorum signs.
* @param verifyingContract The contract consuming the approvals. Binding it
* stops an approval collected for one contract being replayed
* against another with the same payload shape.
* @param actionDomain What is being authorized — a per-action constant, so
* an approval for "advance the accounts tree" cannot be replayed as
* one for "revoke an identity".
* @param anchorBlock The Final Chain block the members read tree 1 at to
* decide the roster. Bound here so every approval in a round names
* the same view; checked against `ANCHOR_WINDOW` by `require_`.
* @param payloadDigest The action's own committed content. Callers MUST
* include a nonce or a monotonic counter in it; nothing here can
* tell a replay of round 7 from a fresh round 7.
*/
function digest(
address verifyingContract,
bytes32 actionDomain,
uint64 anchorBlock,
bytes32 payloadDigest
) internal view returns (bytes32) {
return keccak256(
abi.encode(
DOMAIN_PQ_QUORUM,
block.chainid,
verifyingContract,
actionDomain,
anchorBlock,
payloadDigest
)
);
}
/**
* @notice Reverts unless at least `threshold` distinct members holding
* `roleMask` have signed `quorumDigest`.
* @param registry Where public keys and roles come from. Not a parameter
* for flexibility — a parameter so the caller's own immutable
* registry address is what is used, rather than one from calldata.
* @param requiredAlgorithm `ALG_ANY` to accept either scheme.
* @param anchorBlock The anchor the digest was built over. Refused if it is
* ahead of this block or more than `ANCHOR_WINDOW` behind it.
* @param requireSeal Whether every approval must also carry a valid `seal`
* by the member's `activeSeal` key — the execution class.
* @return valid The number of approvals that verified, which is at least
* `threshold` if this returns at all.
*
* @dev Every failure reverts with the offending signer named. A quorum that
* silently skipped bad approvals and counted the rest would let a
* misconfigured co-signer sit broken indefinitely: the threshold would keep
* being met by the others and nothing would say one member had stopped
* contributing. That is exactly the failure this program has already had,
* in `fanOut`, where a per-chain advance failure was recorded and execution
* continued.
*/
function require_(
FinalIdentityRegistry registry,
Approval[] calldata approvals,
bytes32 quorumDigest,
uint256 roleMask,
uint256 threshold,
uint8 requiredAlgorithm,
uint64 anchorBlock,
bool requireSeal
) internal view returns (uint256 valid) {
if (threshold == 0) revert ThresholdIsZero();
if (anchorBlock > block.number) revert AnchorAhead(anchorBlock, block.number);
if (block.number - anchorBlock > ANCHOR_WINDOW) revert AnchorStale(anchorBlock, block.number);
bytes memory message = abi.encodePacked(quorumDigest);
address previous = address(0);
uint256 n = approvals.length;
for (uint256 i = 0; i < n; i++) {
Approval calldata a = approvals[i];
// Strictly ascending. `address(0)` as the initial value works
// because it can never be a registered signer.
if (a.signer <= previous) revert SignersNotAscending(previous, a.signer);
previous = a.signer;
if (!registry.hasRole(a.signer, roleMask)) revert SignerLacksRole(a.signer, roleMask);
if (requiredAlgorithm != ALG_ANY && a.algorithm != requiredAlgorithm) {
revert WrongAlgorithm(a.signer, a.algorithm, requiredAlgorithm);
}
if (!_verify(registry, a, message)) revert BadSignature(a.signer, a.algorithm);
if (requireSeal && !_verifySeal(registry, a, message)) revert BadSeal(a.signer);
valid++;
}
if (valid < threshold) revert ThresholdNotMet(valid, threshold);
}
/// @notice Non-reverting form, for views and for callers that want to
/// report rather than refuse.
function count(
FinalIdentityRegistry registry,
Approval[] calldata approvals,
bytes32 quorumDigest,
uint256 roleMask,
uint8 requiredAlgorithm,
uint64 anchorBlock,
bool requireSeal
) internal view returns (uint256 valid) {
if (anchorBlock > block.number || block.number - anchorBlock > ANCHOR_WINDOW) return 0;
bytes memory message = abi.encodePacked(quorumDigest);
address previous = address(0);
uint256 n = approvals.length;
for (uint256 i = 0; i < n; i++) {
Approval calldata a = approvals[i];
if (a.signer <= previous) return valid;
previous = a.signer;
if (!registry.hasRole(a.signer, roleMask)) continue;
if (requiredAlgorithm != ALG_ANY && a.algorithm != requiredAlgorithm) continue;
if (!_verify(registry, a, message)) continue;
if (requireSeal && !_verifySeal(registry, a, message)) continue;
valid++;
}
}
/// @dev The seal: SLH-DSA-SHAKE-256s by the member's `activeSeal` key over
/// the same digest. A member with no seal key on record cannot seal, and an
/// approval with no seal bytes is not one.
function _verifySeal(
FinalIdentityRegistry registry,
Approval calldata a,
bytes memory message
) private view returns (bool) {
bytes memory key = registry.activeSealKeyOf(a.signer);
if (key.length == 0 || a.seal.length == 0) return false;
return FinalChainPrecompiles.verifySlhDsa(key, message, a.seal);
}
/// @dev Verifies one approval against the key the REGISTRY holds for that signer, never against a key
/// supplied in the approval. A key passed as an argument proves nothing, because anyone holding a
/// keypair can sign under it; reading from storage is what makes the verdict re-derivable from public
/// state rather than a claim by whoever assembled the call.
/// @param registry The identity registry that holds each signer's live keys.
/// @param a The approval being verified.
/// @param message The exact bytes the approval must cover.
/// @return valid True when the signature verifies under the signer's live key for the declared algorithm.
function _verify(
FinalIdentityRegistry registry,
Approval calldata a,
bytes memory message
) private view returns (bool) {
// The LIVE pair, always. The recovery pair authorizes rotating this
// account's own credentials and NOTHING else — a quorum that accepted
// it would hand the recovery keys everyday authority, which is exactly
// the separation the two stages exist to draw.
if (a.algorithm == ALG_ML_DSA_87) {
return FinalChainPrecompiles.verifyMlDsa87(
registry.activeTransactionKeyOf(a.signer), message, a.signature
);
}
if (a.algorithm == ALG_SLH_DSA_SHAKE_256S) {
return FinalChainPrecompiles.verifySlhDsa(
registry.activeAccessKeyOf(a.signer), message, a.signature
);
}
// Any other id is a refusal, never a default — including the KEM ids
// (3, 7) and the reserved FN-DSA id (6), none of which is a signature
// scheme this quorum verifies.
return false;
}
}
contracts/finalchain/FinalStateTrees.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may deploy this state-tree contract as the state
// plane of a Final DeFi Protocol chain, and may operate that chain.
// 2. Integrators, indexers, operators and end users may read every tree, take
// inclusion proofs, branch roots, tree roots and round roots from it, and
// write into a tree they hold the quorum, the writer seat or the
// configuration authority for, as part of their integration with the Final
// DeFi Protocol.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this state-tree contract or a competing state
// plane derived from it without permission prior to the Change Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
import {FinalIdentityRegistry} from "./FinalIdentityRegistry.sol";
import {FinalChainTime} from "./FinalChainTime.sol";
import {FinalPqQuorum} from "./FinalPqQuorum.sol";
import {FinalPlaneSweep} from "./FinalPlaneSweep.sol";
/// @title Chain Source
/// @notice The one question `syncIdentities` asks the asset registry.
/// @dev An interface rather than an import of `FinalAssetRegistry`, which
/// imports this file: the registry is tree 6's writer and holds the trees
/// as an immutable, so the dependency runs that way and this is the one
/// read that runs the other.
interface IChainSource {
/// @notice Every chain reference the asset registry currently has enabled.
/// @dev Read once per `syncIdentities` batch, so a service account's
/// `deployedChains` table is DERIVED from registry state instead of
/// being supplied by the caller. A caller-chosen table would let
/// anyone place a service identity on a chain of their choosing,
/// which is why the projection reads and never accepts.
/// @return The enabled chain references, in the registry's own order.
function enabledChainRefs() external view returns (bytes32[] memory);
}
/// @title Slot Key Source
/// @notice The one question {FinalStateTrees.syncSlotKeyLeaves} asks the
/// slot-key registry: the leaf value for one member's slot — the
/// registry's own verdict, zero when the slot holds nothing usable.
interface ISlotKeySource {
/// @notice The leaf value one member's slot-key ring position carries.
/// @dev The registry decides; this contract only copies. Zero is the
/// answer for a slot that never held a key and for one whose window
/// has passed, so re-projecting a lapsed slot retires its leaf.
/// @param member The co-signer whose slot key is being read.
/// @param slotIndex The slot the key belongs to, before the ring modulus.
/// @return The registry's leaf value, or zero when the slot holds nothing usable.
function slotKeyLeafOf(address member, uint64 slotIndex) external view returns (bytes32);
}
/// @title Endpoint Source
/// @notice The one question {FinalStateTrees.syncEndpointLeaves} asks the
/// endpoint registry: the leaf value for one tunnel endpoint — the
/// registry's own verdict (certificate hash, status, expiry, region),
/// zero when nothing is registered under the id.
interface IEndpointSource {
/// @notice The leaf value one tunnel endpoint carries.
/// @dev The registry admitted the certificate under its own quorum with
/// the holder's proof of possession, so this read carries a verdict
/// rather than a claim. Zero means nothing stands under the id.
/// @param endpointId The endpoint's certificate subject key id.
/// @return The registry's leaf value, or zero when nothing is registered under the id.
function endpointLeafOf(bytes32 endpointId) external view returns (bytes32);
}
/**
* @title Final State Trees
* @notice Final Chain's state plane: eight fixed-depth Merkle trees, and the rounds that publish all
* eight of their roots as one contemporaneous snapshot.
*
* @dev This contract runs on the project's own reth-based chains and nowhere else. Every signer is
* resolved through an identity registry that verifies post-quantum signatures in precompiles those chains
* alone provide, so a deployment anywhere else cannot authorize a single write. Nothing under
* `contracts/` outside the Final Chain directory imports it, and it takes part in no CREATE2 derivation —
* its address is whatever its deploy transaction produced, never a mined constant that other code pins.
* Gas is deliberately NOT a design constraint here and must not be optimised for: full sibling paths are
* stored, every branch enumerates on chain, and a configuration row keeps its value beside its hash,
* precisely so that no reader ever has to rebuild anything off chain to be sure of it.
*
* **Immutable, and behind no proxy.** There is no upgrade path and no authority that can replace this
* code. Any change to the surface below is a REDEPLOY at a new address, and everything holding the old
* address — the account ledger, the registries, the records contract, every service configured against
* it, every consumer pinning a root — is orphaned the moment that happens and has to be repointed. The
* registry projections into trees 1 and 8 do not travel with a redeploy either: they are derived from the
* registry, so a fresh deployment re-derives them rather than migrating anything.
*
* ## What each tree carries
*
* One tree per domain, because they change at unrelated cadences and a combined tree invalidates every
* outstanding proof on every tick:
*
* | # | tree | holds | cadence |
* |---|---|---|---|
* | 1 | accounts | every Final Wallet's public state | per rotation / creation |
* | 2 | phi | the PHI record: per (wallet, chain) balances, the lock, exposures | per publisher round |
* | 3 | vasset | issued vAsset supply and backing, per (asset, chain) | per settlement |
* | 4 | oracle | published prices and their inputs | ~10 s; 1 s for morph and fee assets |
* | 5 | settlement | chain and asset registry roots | rarely |
* | 6 | allowlist | assets, chains, policy, price sources, DEX deployments | rarely |
* | 7 | intents | intent status, ring-keyed over the posting sequence | per posting |
* | 8 | identity | the wallet-creation admission set, projected from the registry | per identity mutation |
*
* ## Tree 1 is READ, never rebuilt
*
* Tree 1 is a Final Wallet's public state and the SOURCE OF TRUTH every execution chain projects from.
* The sanctioned way to ask it a question is {proofFor} for the sibling path and {liveRoot} for the root
* each chain republishes — {branchProofFor} with {branchRoot} to prove against a branch instead,
* {roundProofFor} with {roundRootAt} to prove against a published round. Those entrypoints are the whole
* interface, and their answers are the only ones that verify.
*
* Do NOT fold the same leaves off chain. This tree is FIXED DEPTH — `DEPTH` levels, with a branch subtree
* at `BRANCH_DEPTH` — zero-padded to that depth, and INSERTION-ORDERED: a key keeps the slot it was first
* handed, permanently, and empty slots hash as the empty subtree rather than being skipped. A rebuild
* that sorts its leaves, or sizes itself `log2(n)` to the number of leaves present, is a DIFFERENT tree.
* Its root is not this root, no proof against it verifies anywhere, and nothing in the failure names the
* cause: the execution chain simply refuses a proof that looks perfectly well formed.
*
* ## Who may write which tree
*
* Four kinds of door, and every tree sits on exactly one of the first three:
*
* - **A service quorum.** {setLeaves} for trees 5 and 6, {setAccountStates} for tree 1: at least
* `threshold[treeId]` approvals from members holding `writerRole[treeId]`, each an ML-DSA-87 vote over
* a digest binding the tree, its nonce and the whole batch. Tree 1's round additionally carries each
* member's SLH-DSA seal, because a leaf there states who an account IS on every chain.
* - **A typed writer.** Trees 2, 3 and 4 are reachable only through {writeTyped}, from the records
* contract, which holds the preimage behind each leaf and computes the hash from it. {setLeaves}
* refuses those three outright, so a stored value can never drift from the commitment beside it.
* - **A writer contract.** `treeWriter[treeId]` writes its tree with no quorum at all: the account ledger
* for tree 1, the intent log for tree 7, the ledger again for tree 8's user admissions. Trees 7 and 8
* have no quorum path whatsoever — {setLeaves} refuses both.
* - **The configuration authority.** Branch 0 of every tree through {setConfig}, plus the pointers,
* rosters and thresholds themselves. Never a tree's own writer or quorum: what a service states is not
* authority over how that service is configured.
*
* `treeWriter[1]` being the account ledger, with no service quorum layered on top, is the design and not
* a gap. A writer contract is not a key: its rules are its bytecode, it has no owner and no proxy, and it
* authorizes every transition by verifying the ACCOUNT HOLDER'S own SLH-DSA credential against the
* commitment this chain holds. That is stronger evidence than a K-of-N of our own services attesting to
* what they read. A quorum on top would be strictly worse than nothing — it would let operators withhold
* approval from a user rotating a stolen key, which is a censorship power over the exact operation the
* account plane exists to make possible.
*
* ## Seeding the chain and asset trees
*
* Trees 5 and 6 are the two a fresh plane cannot infer. Tree 5 carries the settlement chain and asset
* registry roots; tree 6 carries the allowlist those roots stand over — supported chains, supported
* assets, policy, price sources, DEX deployments. Both are quorum-written, and both are expected to be
* SEEDED before the plane is usable: an execution chain copies its chain set and its asset set from these
* roots, so an unseeded pair means every settlement toward a chain is refused at the source and no vAsset
* ever registers. A test plane seeds the test chains; a production plane seeds the production chains and
* their assets. `chainSource` belongs in the same window, because `syncIdentities` derives a service
* account's `deployedChains` table from the enabled chain set, and an unset source quietly produces
* service leaves that exist on Final Chain alone.
*
* The bootstrap ordering is load bearing in one more place: {configureTree} refuses a threshold no live
* roster can meet, so members are registered first and trees configured after. A plane whose trees were
* never configured accepts no quorum write at all while looking perfectly healthy from outside.
*
* ## The hash shape is not a choice
*
* Leaves hash as `keccak256(0x00 ‖ leaf)` and internal nodes as
* `keccak256(0x01 ‖ lo ‖ hi)` with the pair sorted. That is
* `FinalMerkle.verifyTaggedSortedProof`, verbatim, which is what
* `FinalWalletFactory.syncAccountState` and `FinalSettlement` already run on
* every supported chain. A proof produced here is consumed there with no
* translation and no contract change, and tree 1's leaf preimage is exactly
* `FinalWalletFactory.accountStateLeafHash` — same fields, same order, the
* `deployedChains` table `abi.encode`d like every other field.
*
* Getting this wrong is not a compile error anywhere. It is a root every chain
* silently rejects, with nothing pointing at the cause.
*
* ## Positional slots under a sorted-pair tree
*
* Sorted pairs make a proof position-agnostic, which is why it carries no
* direction bits. That does not stop the TREE from being positional, and here
* it is: every key gets a permanent slot, so a single leaf update is `DEPTH`
* hashes instead of a rebuild over every leaf. The verifier neither knows nor
* needs to know that a slot exists.
*
* ## Branches
*
* The slot space of every tree is cut into `BRANCH_COUNT` branches by the top
* `BRANCH_BITS` of the slot: a branch is a subtree with a permanent place, its
* root is one internal node, and a leaf's path to the tree root passes through
* it. Branches hold what belongs to the same domain but not to the same rows
* — branch 0 is the owning service's CONFIGURATION on every tree, tree 8 adds
* the owner → wallets index and the co-signers' slot keys beside the admission
* set — and they are chosen over more trees because a branch shares its
* tree's authority doors and writer, while a tree would need its own. A leaf
* proves against its branch root with `BRANCH_DEPTH` siblings, against the
* tree root with `DEPTH`, against the round root with `ROUND_DEPTH`: one path,
* cut at three heights, one verifier.
*
* ## Rounds, and why the live roots are not the product
*
* `setLeaves` moves a tree. It does not publish one. A consumer that fetched
* eight roots one at a time would get a price proof from one moment and a
* roster proof from another, and something delisted in between would still
* verify.
*
* `publishRound` snapshots all eight together, and folds them into ONE round
* root — the tree roots as the level-`DEPTH` nodes of a depth-`ROUND_DEPTH`
* tree, tree `t` at position `t` — so a single word commits to the whole
* plane and any leaf in it proves against that word with four more siblings.
* A round is the unit a consumer pins, and it is the only thing this contract
* promises is contemporaneous. The execution chains keep anchoring per-tree
* roots (identity, account state, registry roots): those must move at their
* own cadence, not at the oracle's.
*/
contract FinalStateTrees is FinalPlaneSweep {
// ---------------------------------------------------------------- trees
/// @notice Every Final Wallet's public state. The source of truth other
/// chains copy through `syncAccountState`.
uint8 public constant TREE_ACCOUNTS = 1;
/// @notice The PHI record, per `(wallet, chain)`: balances, the lock, its
/// terms, the exposures carved from it and the accrual between reconciliations.
uint8 public constant TREE_PHI = 2;
/// @notice vAsset supply and backing.
uint8 public constant TREE_VASSET = 3;
/// @notice Oracle prices and their inputs.
uint8 public constant TREE_ORACLE = 4;
/// @notice Settlement chain and asset registry roots.
uint8 public constant TREE_SETTLEMENT = 5;
/// @notice Which assets and chains are supported.
uint8 public constant TREE_ALLOWLIST = 6;
/// @notice Intent status, keyed by a RING over the posting sequence.
/// @dev The search structure beside `FinalBundleLog`'s permanent record.
/// Written only by `FinalIntentLog` through `treeWriter[7]` — the tree-1
/// argument verbatim: the log verified the bond, the commitment, the
/// approval and the consume itself, and a service quorum on top would be a
/// censorship point over posting. Slots are permanent and intents are
/// unbounded flow, so the log recycles keys modulo `CAPACITY`: the tree is
/// an index with a ~1M-posting retention window, never the record.
uint8 public constant TREE_INTENTS = 7;
/// @notice The wallet-creation admission set — the identity leaves
/// (`keccak256(DOMAIN_IDENTITY_LEAF ‖ serial ‖ keysHash)`) every execution
/// chain's gateway verifies certificates against.
/// @dev The root the gateways anchor as `currentIdentityRoot`, CONTINUOUS
/// over this tree: an admission or a revocation is live the moment it
/// lands here, with no off-chain folding step standing between the two.
/// Two feeders, one per identity plane, and NO quorum door for either:
///
/// - SERVICE identities: {syncIdentityLeaves}, the permissionless
/// projection of `FinalIdentityRegistry`'s own verdict — the registry
/// calls it same-tx on every identity mutation, and anyone may call it
/// to retire a leaf whose standing lapsed by TIME (expiry moves no
/// registry storage, so only a projection pass can zero it).
/// - USER identities: `treeWriter[8]` — `FinalAccountLedger`, which
/// computes the leaf from the genesis certificate fields it verified
/// under its opener quorum and writes it once at `openAccount`. A user
/// admission leaf is permanent by construction: the certificate IS the
/// address, rotation never changes it, and a post-rotation creation on
/// a new chain reads PUBLISHED account state out of tree 1, never the
/// certificate's genesis keys.
///
/// A quorum of service signatures must not be able to state an identity
/// neither ruler decided, so `setLeaves` refuses this tree outright.
uint8 public constant TREE_IDENTITY = 8;
/// @notice Count, for iteration. Trees are 1-indexed; 0 is not a tree.
/// @notice Tree 9 — compliance: the approved set (branch 1), revocations (2), per-jurisdiction
/// counters (3) and minutes-lived action attestations (4); branch 0 pins the jurisdiction
/// policy in force and the attestation life. Typed-only: `FinalStateRecords` writes it under
/// the REGISTRAR quorum (an attestation is an admission) through `writeTypedInBranch`, and
/// the presale ledger mirrors its counters through the same companion; no `setLeaves` door
/// — no set of service signatures may attest what the provider and the screening did not
/// decide. Leaves are `FinalComplianceLeaves`; nothing in them names a person.
uint8 public constant TREE_COMPLIANCE = 9;
/// @notice Number of trees. The round root has room for 2**FOREST_BITS; a new tree is a redeploy.
uint8 public constant TREE_COUNT = 9;
/// @notice Tree height: 2^`DEPTH` slots per tree, laid out as 16 BRANCHES
/// of 2^20. The top `BRANCH_BITS` of a slot name the branch, the rest its
/// position inside it.
/// @dev FIXED, and baked into every root this contract produces. A tree is
/// padded to this height with the empty-subtree hash whether it holds one
/// leaf or a million, which is why an off-chain rebuild must use this
/// depth verbatim: a `log2(n)` tree over the same leaves is a different
/// tree and proves nothing here. Raising it is a migration and not a
/// parameter change — every outstanding proof and every root anchored on
/// another chain would have to be replaced in the same instant.
uint256 public constant DEPTH = 24;
/// @notice How many of a slot's top bits name the branch it lives in.
/// @dev `BRANCH_COUNT` is `1 << BRANCH_BITS` and `BRANCH_DEPTH` is
/// `DEPTH - BRANCH_BITS`; the three move together, or the branch a slot
/// belongs to stops matching the subtree its proof passes through.
uint256 public constant BRANCH_BITS = 4;
/// @notice Branches per tree. Ids run `0 .. BRANCH_COUNT - 1`.
/// @dev Sixteen is deliberately generous: an unused branch costs only the
/// empty-subtree hash it contributes, so a domain can grow a new family of
/// rows without a new tree, a new writer or a new authority.
uint8 public constant BRANCH_COUNT = 16;
/// @notice Height of a branch: a leaf proves against its branch root with
/// this many siblings.
uint256 public constant BRANCH_DEPTH = DEPTH - BRANCH_BITS;
/// @notice Slots per branch.
/// @dev The hard ceiling `_set` enforces: a branch that runs out of slots
/// reverts `BranchFull` rather than spilling into its neighbour, because a
/// key in the wrong branch would prove against the wrong branch root.
uint256 public constant BRANCH_CAPACITY = 1 << BRANCH_DEPTH;
/// @notice Slots per tree, all branches together.
uint256 public constant CAPACITY = 1 << DEPTH;
/// @notice How many of the round root's levels sit above the tree roots.
/// @dev The round root is a tree over the tree roots — position `t` holds
/// tree `t`'s root, positions 0 and 9..15 the empty tree — folded with the
/// same node hash. It is literally the root of a depth-`ROUND_DEPTH` tree
/// whose level-`DEPTH` nodes are the eight tree roots, which is what lets
/// one path prove a leaf against it.
uint256 public constant FOREST_BITS = 4;
/// @notice Height of the round tree: a leaf proves against a round root
/// with this many siblings, the last `FOREST_BITS` of them from
/// {roundProofFor}.
uint256 public constant ROUND_DEPTH = DEPTH + FOREST_BITS;
/// @notice Branch 0 of EVERY tree: the configuration of the service that
/// owns the tree — key → one word, the VALUE stored so a contract on this
/// chain reads it directly (`configValue`), the hash in the tree so it is
/// provable wherever a round root is. Written only by {setConfig} under
/// the configuration authority; every other door refuses the branch.
uint8 public constant BRANCH_CONFIG = 0;
/// @notice Branch 1 of every tree: the domain's own rows — accounts, PHI
/// records, vAssets, prices, registry roots, the allowlist, the intent
/// ring, the identity admission set.
uint8 public constant BRANCH_MAIN = 1;
/// @notice Tree 8, branch 2: the owner → wallets index. Key = the owner
/// (`ownerIndexKeyFor`), leaf = {ownerIndexLeafHash} over the ledger's
/// `walletsByOwner(owner)`. Written by tree 8's writer, the ledger, beside
/// every open and every owner transfer — the tree is the search structure,
/// the ledger holds the readable array it proves.
uint8 public constant BRANCH_OWNER_INDEX = 2;
/// @notice Tree 8, branch 3: the co-signers' per-slot KEM publics — a RING
/// of `SLOT_KEY_RING` positions per member, projected from
/// `slotKeySource` by {syncSlotKeyLeaves} exactly as identities are.
uint8 public constant BRANCH_SLOT_KEYS = 3;
/// @notice Tree 8, branch 4: the tunnel endpoints — the Final Node
/// identities a wallet's FNP session terminates at. Key = the endpoint id
/// (`endpointKeyFor`, the certificate's subject key id), leaf = the
/// endpoint registry's verdict, projected from `endpointSource` by
/// {syncEndpointLeaves} exactly as slot keys are. An execution chain never
/// parses an endpoint certificate; it anchors this tree's root and a client
/// proves the leaf against it.
uint8 public constant BRANCH_ENDPOINTS = 4;
/// @notice Slot-key positions per member. A slot index wraps modulo this,
/// so the branch is an index over the recent slots and never fills; 1024
/// members × 1024 positions is the branch exactly.
uint64 public constant SLOT_KEY_RING = 1024;
/// @notice The domain every tree-1 leaf is hashed under.
/// @dev Must equal `FinalWalletFactory.DOMAIN_ACCOUNT_STATE_LEAF` byte for
/// byte, and the leaf's fields must be encoded in the same order on both
/// sides. A field reordered on one side only is not a compile error
/// anywhere: it is a root every execution chain rejects, with nothing
/// pointing at the cause.
///
/// The version suffix is part of the domain, so a leaf built under a
/// different account-state shape hashes into a different domain and cannot
/// verify against this one by accident.
bytes32 public constant DOMAIN_ACCOUNT_STATE_LEAF =
keccak256("FINAL_ACCOUNT_STATE_LEAF_v02");
/// @dev The quorum action every leaf write is approved under — {setLeaves},
/// {setAccountStates} and {writeTyped} share it, so a member recomputes one
/// digest whichever door a batch came through and there is no second
/// approval shape to get wrong.
bytes32 private constant ACTION_SET_LEAVES = keccak256("FinalStateTrees.setLeaves.v01");
/// @notice Configuration action: set a tree's writer role and threshold.
/// @dev Registrar-quorum actions, verified by the registry with this
/// contract as the verifying contract. See `FinalIdentityRegistry.requireRegistrarQuorum`.
bytes32 public constant ACTION_CONFIGURE_TREE = keccak256("FINAL_STATE_TREES_CONFIGURE_TREE_v01");
/// @notice Configuration action: point a tree at its writer contract.
bytes32 public constant ACTION_SET_TREE_WRITER = keccak256("FINAL_STATE_TREES_SET_TREE_WRITER_v01");
/// @notice Configuration action: point `syncIdentities` at the chain set.
bytes32 public constant ACTION_SET_CHAIN_SOURCE = keccak256("FINAL_STATE_TREES_SET_CHAIN_SOURCE_v01");
/// @notice Configuration action: point tree 8's branch 3 at the slot-key registry.
bytes32 public constant ACTION_SET_SLOT_KEY_SOURCE = keccak256("FINAL_STATE_TREES_SET_SLOT_KEY_SOURCE_v01");
/// @notice Configuration action: point tree 8's branch 4 at the endpoint registry.
bytes32 public constant ACTION_SET_ENDPOINT_SOURCE = keccak256("FINAL_STATE_TREES_SET_ENDPOINT_SOURCE_v01");
/// @notice Configuration action: adopt a preceding plane's version and round counters.
bytes32 public constant ACTION_SEED_COUNTERS = keccak256("FINAL_STATE_TREES_SEED_COUNTERS_v01");
/// @notice Configuration action: install the records contract that writes the typed trees.
bytes32 public constant ACTION_SET_TYPED_WRITER = keccak256("FINAL_STATE_TREES_SET_TYPED_WRITER_v01");
/// @notice Configuration action: write rows into a tree's branch 0.
bytes32 public constant ACTION_SET_CONFIG = keccak256("FINAL_STATE_TREES_SET_CONFIG_v01");
/// @dev Tree-1 key domain. A full-width hash rather than the packed address
/// it came from, which matters: an address key occupies only the low 160
/// bits, so a hashed key colliding with one needs ~2^96 work rather than a
/// full collision. That is expensive but not comfortable, and the
/// consequence would be a service identity landing in a wallet's slot.
bytes32 private constant DOMAIN_ACCOUNT_KEY = keccak256("FinalStateTrees.key.account.v01");
/// @dev Tree-8 admission key domain, separated from the tree-1 domain for
/// the same reason: one account's two keys must never be the same word.
bytes32 private constant DOMAIN_IDENTITY_TREE_KEY = keccak256("FinalStateTrees.key.identity.v01");
/// @dev Tree 8, branches 2 and 3, and branch 0 of every tree. Each is its
/// own domain so a key can never land in another branch's slot by
/// construction — `_set` refuses a key whose slot sits in a different
/// branch, and the domain is what makes that refusal unreachable.
bytes32 private constant DOMAIN_OWNER_INDEX_KEY = keccak256("FinalStateTrees.key.ownerIndex.v01");
/// @dev Tree 8, branch 3: one key per `(member, ring position)` pair.
bytes32 private constant DOMAIN_SLOT_KEY = keccak256("FinalStateTrees.key.slotKey.v01");
/// @dev Tree 8, branch 4: one key per tunnel endpoint id.
bytes32 private constant DOMAIN_ENDPOINT_KEY = keccak256("FinalStateTrees.key.endpoint.v01");
/// @dev Branch 0 of every tree: one key per `(name, sub)` configuration row.
bytes32 private constant DOMAIN_CONFIG_KEY = keccak256("FinalStateTrees.key.config.v01");
/// @notice Leaf domain for the owner index in tree 8, branch 2.
/// @dev Separate from the key domain above so the leaf and the slot it
/// occupies can never be confused for one another by a reader that has
/// only one of the two.
bytes32 public constant DOMAIN_OWNER_INDEX_LEAF = keccak256("FINAL_OWNER_INDEX_LEAF_v01");
/// @notice Leaf domain for configuration rows in branch 0 of every tree.
/// @dev The leaf binds the tree id as well as the key and value, so the
/// same row written into two trees produces two different leaves and a
/// proof cannot be carried from one tree's branch 0 to another's.
bytes32 public constant DOMAIN_CONFIG_LEAF = keccak256("FINAL_CONFIG_LEAF_v01");
// -------------------------------------------------------------- storage
/// @notice The registry every signer is resolved through. Immutable so the
/// quorum can never be pointed at a registry supplied in calldata.
FinalIdentityRegistry public immutable registry;
/// @notice Approvals required per tree.
///
/// @dev Per-tree and not a scalar, because each tree is gated by a
/// DIFFERENT role — account co-signers, PHI, vAsset and oracle
/// publishers, registry publishers — so K is a property of that
/// tree's roster, not of the contract. All six read 2 today; that is
/// a deploy-time default, not an invariant, and collapsing them would
/// put the oracle roster's quorum on the account co-signers'.
///
/// The VALUE is a full word: it is a quantity compared against a live
/// member count, and every other threshold in the system is `uint256`.
/// The KEY is `uint8` because that is what a tree id is here — six
/// `uint8` constants, every parameter, every event, every error,
/// `_assertTree`, and the ten sibling mappings below. Widening it
/// would buy nothing (a narrow key is padded to 32 bytes before
/// hashing, so the slot is identical) and cost the getter's selector
/// on a contract that is live on both Final Chains.
mapping(uint8 treeId => uint256) public threshold;
/// @notice Role a signer must hold to write to a tree.
mapping(uint8 treeId => uint256) public writerRole;
/// @notice Raw (untagged) leaf value by tree and slot.
/// @dev The tag is applied when the leaf is hashed, never when it is
/// stored, so what a caller wrote is what {leafOf} hands back.
mapping(uint8 => mapping(uint256 => bytes32)) private _leaf;
/// @notice Internal nodes, levels 1..`DEPTH`, by tree, level and index.
/// @dev Level 0 is DERIVED from `_leaf` rather than duplicated here, so a
/// leaf lives in exactly one place and the two can never disagree. An
/// unwritten position reads zero and falls through to `_zero[level]`.
mapping(uint8 => mapping(uint256 => mapping(uint256 => bytes32))) private _node;
/// @notice Empty-subtree hash per level, computed once at construction.
/// @dev Sized to the ROUND root's height, not the tree's, because the
/// round tree's unused positions are themselves empty trees. Built in
/// the constructor rather than declared as constants: it depends on
/// the tagging, and a constant table that drifted from the tagging
/// would produce roots nothing can verify, silently, since both sides
/// would still be internally consistent.
bytes32[ROUND_DEPTH + 1] private _zero;
/// @notice Permanent slot for a key, stored 1-based so 0 means unassigned.
/// @dev The slot's top `BRANCH_BITS` are the branch the key lives in, and
/// the assignment is permanent: a key handed a slot keeps it for the
/// life of the contract. This is what makes an update `DEPTH` hashes
/// rather than a rebuild, and what makes the tree insertion-ordered.
mapping(uint8 => mapping(bytes32 => uint256)) private _slotPlusOne;
/// @notice The key a slot was handed to — the reverse of `_slotPlusOne`.
/// @dev Lets any branch enumerate on chain ({keyAt} over
/// `0 .. branchSlotsUsed`) with no log window and no indexer. Costs
/// one extra word per NEW key, never one per update.
mapping(uint8 => mapping(uint256 => bytes32)) private _keyAt;
/// @notice Slots handed out per tree, all branches together.
mapping(uint8 => uint256) public slotsUsed;
/// @notice Slots handed out per branch — the next free position in it.
/// @dev Per branch and not per tree, because a branch is a fixed region of
/// the slot space: positions are allocated from the branch's own base
/// so a key can never be handed a slot outside the branch it belongs
/// to, and `BranchFull` is raised rather than spilling into the next.
mapping(uint8 => mapping(uint8 => uint256)) private _branchSlotsUsed;
/// @notice The VALUE behind a configuration row (branch 0), by tree and key.
/// @dev Kept beside the leaf hash so a contract on this chain reads the row
/// directly through {configValue} while the same row stays provable
/// off chain against a round root — one source for the fleet, the
/// contracts and any explorer, rather than one per reader.
mapping(uint8 => mapping(bytes32 => bytes32)) private _configValue;
/// @notice Live root per tree. Moves on every `setLeaves`.
mapping(uint8 treeId => bytes32) public liveRoot;
/// @notice Writes applied per tree, for change detection between rounds.
mapping(uint8 treeId => uint64) public treeVersion;
/// @notice A contemporaneous snapshot of all eight roots, and the one
/// round root that folds them.
struct Round {
/// @dev Live root per tree at the instant of the snapshot, indexed by
/// the `TREE_*` constants. Index 0 is unused, so a tree id needs
/// no translation.
bytes32[TREE_COUNT + 1] roots;
/// @dev The single word committing to all eight — the roots folded as
/// the level-`DEPTH` nodes of a depth-`ROUND_DEPTH` tree.
bytes32 roundRoot;
/// @dev Block the snapshot was taken in, for a consumer reconciling a
/// round against chain history.
uint64 blockNumber;
/// @dev Snapshot instant in MILLISECONDS, like every instant on this
/// chain, so a reader never has to guess the unit.
uint64 timestamp;
}
/// @notice Published rounds, 1-indexed. Round 0 is "nothing published".
/// @dev Kept forever: a consumer pinning an old round can still fetch the
/// roots it verified against. Only rounds this deployment published
/// are here — {seedCounters} moves the counter, never the history.
mapping(uint64 => Round) private _rounds;
/// @notice Highest published round.
uint64 public round;
/// @notice Tree versions as of the last published round.
/// @dev The change detector {publishRound} reads: a round that would carry
/// nothing new is refused, so the round number cannot be advanced by
/// anyone with gas to spend.
mapping(uint8 => uint64) private _publishedVersion;
/// @notice Per-tree nonce, bound into every quorum digest.
mapping(uint8 treeId => uint64) public nonce;
/**
* @notice A CONTRACT allowed to write one tree without a quorum.
*
* @dev Exactly one per tree, and today exactly one exists: tree 1's is
* `FinalAccountLedger`.
*
* This looks like a hole and is the opposite. The quorum on `setLeaves`
* exists because a tree's writer is otherwise one key deciding what the
* chain states. A writer contract is not a key — its rules are its
* bytecode, it has no owner and no proxy, and tree 1's writer authorizes
* every change by verifying the ACCOUNT HOLDER'S own post-quantum signature
* in this chain's precompiles. That is strictly stronger evidence than a
* K-of-N of our own services attesting to what they read.
*
* Keeping the quorum on top of it would be actively worse: our fleet could
* then withhold approval from a user rotating a stolen key, which is a
* censorship power over the exact operation the account plane exists to
* make possible.
*
* The writer is set on the same bootstrap window as `configureTree` and can
* be moved by a registrar afterwards — an immutable pointer would mean a
* ledger upgrade abandons the tree it writes.
*/
mapping(uint8 treeId => address) public treeWriter;
/**
* @notice Where `syncIdentities` reads the chain set from — the asset
* registry, which is also tree 6's writer.
*
* @dev A service identity is a Final Wallet whose address is the same on
* every EVM chain, so its tree-1 `deployedChains` table is derivable: one
* `(chainRef, itself)` row per chain the registry has enabled. The table
* is DERIVED from state rather than supplied by the caller precisely so
* that `syncIdentities` can stay permissionless — a caller-chosen table
* would let anyone place a service identity on a chain of their choosing.
*
* Unset (zero) means services carry an empty table and exist on Final
* Chain alone, which is what a plane looks like before its registry is
* seeded. Same configuration gate as `setTreeWriter`, because pointing this
* at a different contract changes what every service leaf says.
*/
address public chainSource;
/// @notice Where {syncSlotKeyLeaves} reads the co-signers' slot keys from
/// — the slot-key registry, whose verdict tree 8's branch 3
/// projects. Same configuration gate as `chainSource`; unset means
/// the branch cannot be written.
address public slotKeySource;
/// @notice The endpoint registry whose verdict tree 8's branch 4 projects.
address public endpointSource;
/// @notice The one contract admitted to {writeTyped}: `FinalStateRecords`,
/// which holds the preimages behind trees 2, 3 and 4 and computes
/// their keys and hashes. Same configuration gate as `treeWriter`.
address public typedWriter;
// --------------------------------------------------------------- events
/// @notice A batch of leaves landed in a tree and moved its live root.
/// @dev Emitted once per write door call, not once per leaf, and always
/// after the root has settled — so `newRoot` is the value {liveRoot}
/// answers from that block onward.
/// @param treeId The tree that moved.
/// @param count Leaves in the batch. Zero is possible for an empty call.
/// @param newRoot The tree's live root after the batch.
/// @param treeVersion The tree's write counter after the batch.
event LeavesSet(uint8 indexed treeId, uint256 count, bytes32 newRoot, uint64 treeVersion);
/// @notice Every tree's root was snapshotted into a new round.
/// @param round The round number, one above its predecessor.
/// @param blockNumber Block the snapshot was taken in.
/// @param timestamp Snapshot instant, in milliseconds.
event RoundPublished(uint64 indexed round, uint64 blockNumber, uint64 timestamp);
/// @notice A tree's writer role and approval threshold were installed.
/// @param treeId The tree configured.
/// @param writerRole Role a signer must hold to approve a write to it.
/// @param threshold Approvals a write needs; zero leaves the tree closed.
event TreeConfigured(uint8 indexed treeId, uint256 writerRole, uint256 threshold);
/// @notice A tree's quorum-free writer contract was installed or moved.
/// @param treeId The tree whose writer changed.
/// @param writer The contract now allowed to write it; zero removes the path.
event TreeWriterSet(uint8 indexed treeId, address writer);
/// @notice The contract `syncIdentities` reads the enabled chain set from was set.
/// @param source The asset registry now consulted; zero means no chain set.
event ChainSourceSet(address source);
/// @notice The registry tree 8's branch 3 projects slot keys from was set.
/// @param source The slot-key registry now consulted; zero closes the branch.
event SlotKeySourceSet(address source);
/// @notice The registry tree 8's branch 4 projects endpoints from was set.
/// @param source The endpoint registry now consulted; zero closes the branch.
event EndpointSourceSet(address source);
/// @notice A fresh plane adopted a preceding plane's counters.
/// @dev Carries the counters only. The roots behind those rounds stay with
/// the plane that published them, so {roundRootAt} below the seed
/// answers zero on this one.
/// @param round The round number this plane continues from.
/// @param versions Per-tree write counters, indexed by tree id; index 0 unused.
event CountersSeeded(uint64 round, uint64[] versions);
/// @notice The records contract admitted to the typed trees was installed.
/// @param writer The contract now allowed through {writeTyped}.
event TypedWriterSet(address writer);
/// @notice One configuration row was written into a tree's branch 0.
/// @param treeId The tree whose owning service the row configures.
/// @param key The row's branch-0 key, as {configKey} computes it.
/// @param value The row's single word of value.
event ConfigSet(uint8 indexed treeId, bytes32 indexed key, bytes32 value);
// --------------------------------------------------------------- errors
/// @notice A tree id outside `1 .. TREE_COUNT` was supplied. Zero is not a tree.
/// @param treeId The rejected id.
error UnknownTree(uint8 treeId);
/// @notice Two parallel arrays did not have the same length, or a batch was empty
/// where at least one row is required.
/// @param keys Length of the key array.
/// @param leaves Length of the value array.
error LengthMismatch(uint256 keys, uint256 leaves);
/// @notice A branch has handed out every slot it owns and cannot take a new key.
/// @dev Raised rather than spilling into the neighbouring branch: a key in
/// the wrong branch would prove against the wrong branch root.
/// @param treeId The tree the branch belongs to.
/// @param branch The exhausted branch.
error BranchFull(uint8 treeId, uint8 branch);
/// @notice A branch id at or above `BRANCH_COUNT` was supplied.
/// @param branch The rejected id.
error UnknownBranch(uint8 branch);
/// @notice A key already holds a slot in another branch of this tree.
/// @dev Slots are permanent, so a key cannot be moved between branches.
/// Reaching this means two callers disagree about where a row lives.
/// @param treeId The tree involved.
/// @param key The key whose slot is already assigned.
/// @param have The branch the key's slot actually sits in.
/// @param want The branch the caller tried to write it into.
error BranchMismatch(uint8 treeId, bytes32 key, uint8 have, uint8 want);
/// @notice Branch 0 is written by `setConfig` alone.
/// @dev Every other door refuses it, so a tree's writer or quorum can never
/// restate the configuration of the service that feeds it.
/// @param treeId The tree whose branch 0 was targeted.
error ConfigBranchReserved(uint8 treeId);
/// @notice Tree 8's branch 3 was written while no slot-key registry is installed.
error SlotKeySourceUnset();
/// @notice Tree 8's branch 4 was written while no endpoint registry is installed.
error EndpointSourceUnset();
/// @notice Counters can be seeded only into a plane that has published nothing.
/// @dev Seeding a plane that already moved would rewind counters consumers
/// have compared against, so it is refused rather than reconciled.
error NotFresh();
/// @notice The seeded version array was not one entry per tree plus the unused index 0.
/// @param given The length supplied.
error VersionCountMismatch(uint256 given);
/// @notice The tree has no threshold installed, so no quorum write can be authorized.
/// @param treeId The unconfigured tree.
error TreeNotConfigured(uint8 treeId);
/// @notice A round was requested while no tree has moved since the last one.
/// @dev The round number is therefore not advanceable by anyone with gas
/// to spend, and a round always means something changed.
error NothingToPublish();
/// @notice The key holds no slot in this tree, so there is nothing to prove or read.
/// @param treeId The tree searched.
/// @param key The key with no slot.
error UnknownKey(uint8 treeId, bytes32 key);
/// @notice The caller is not the writer seat or typed writer this door requires.
/// @param caller The rejected address.
error NotAuthorized(address caller);
/// @notice A round was asked for on a plane that has published none, or one above the latest.
error NoRounds();
/// @notice A threshold was configured above the number of members who could meet it.
/// @dev Refused at configuration time so a tree is never installed already
/// unwritable. Register the roster first; that ordering is the point.
/// Revocation can still walk a live tree into this state later, which
/// is what {quorumHealth} exists for — revocation must never be
/// blocked on quorum arithmetic.
/// @param treeId The tree being configured.
/// @param live Members currently holding the role.
/// @param required Approvals the rejected configuration would demand.
error ThresholdUnreachable(uint8 treeId, uint256 live, uint256 required);
/// @notice Trees 7 and 8 take no quorum writes — only their writer
/// contract (and, for tree 8, the registry projection).
/// @dev An intent's status is what the intent log verified and an identity
/// is what the registry or the ledger verified. No set of service
/// signatures can make a different answer true, so there is no quorum
/// door to refuse at — the door does not exist.
/// @param treeId The writer-only tree a quorum write was aimed at.
error WriterOnlyTree(uint8 treeId);
/// @notice `setLeaves` was called on a tree that has a typed writer.
/// @dev Trees 2, 3 and 4 keep the leaf's preimage beside its hash so a
/// consumer can read the VALUE. An untyped write sets the hash and
/// cannot set the preimage — the pair would disagree, and the stored
/// value would look authoritative while committing to nothing. The
/// typed entrypoint is not a convenience over this one; it is the
/// only door.
/// @param treeId The typed tree an untyped write was aimed at.
error TypedTreeOnly(uint8 treeId);
/// @notice A `deployedChains` row names the zero chain or the zero account,
/// or repeats a chain. A table with either proves nothing about
/// where the account exists.
/// @dev Checked wherever the leaf is hashed, so no door — quorum, writer
/// contract, identity projection — can publish a table a resolver on
/// another chain would read two ways.
/// @param chainRef The offending row's chain reference.
/// @param account The offending row's account on that chain.
error InvalidChainAccount(bytes32 chainRef, bytes32 account);
// ---------------------------------------------------------- constructor
/**
* @notice Pin the identity registry and bring all eight trees up empty.
* @param registry_ The identity registry. Every signer, key and role is
* resolved through it.
* @dev The registry is `immutable`, so no later call can point the quorum
* at a registry supplied in calldata — a roster chosen by the caller is a
* roster that approves whatever the caller wants.
*
* The empty-subtree table is built here rather than as constants because it
* depends on the tagging, and a constant table that drifted from the
* tagging would produce roots nothing can verify — silently, since both
* sides would still be self-consistent.
*
* Every tree starts at the empty root rather than zero, so a consumer can
* tell "this tree holds nothing" from "this contract has never run".
*/
constructor(FinalIdentityRegistry registry_) {
registry = registry_;
// Level 0: the tagged hash of an empty (zero) leaf.
_zero[0] = keccak256(abi.encodePacked(bytes1(0x00), bytes32(0)));
for (uint256 l = 0; l < ROUND_DEPTH; l++) {
// Both children equal, so the sort is a no-op and the order is
// irrelevant — which is the only reason this table is one value per
// level rather than one per position.
_zero[l + 1] = keccak256(abi.encodePacked(bytes1(0x01), _zero[l], _zero[l]));
}
for (uint8 t = 1; t <= TREE_COUNT; t++) {
liveRoot[t] = _zero[DEPTH];
}
}
// ------------------------------------------------------- configuration
/**
* @notice The gate every configuration entrypoint on this contract passes through.
* @dev The registry's bootstrap admin alone while its window is open, the
* sealed `ROLE_REGISTRAR` quorum afterwards. The same window the registry
* uses, for the same reason — every roster has to be installed by someone
* before it can install itself — and the same quorum, because a threshold
* is membership by another name: whoever can set K to one owns the tree.
*
* Not `view`: the registrar path burns the registry's own nonce, so an
* approved configuration payload cannot be replayed at a later block.
* @param actionDomain The `ACTION_*` constant naming what is being configured.
* @param payloadDigest Hash of the arguments this call would apply.
* @param anchorBlock The registrars' roster anchor. Ignored during bootstrap.
* @param approvals The sealed registrar quorum. Empty during bootstrap.
*/
function _requireConfigurationAuthority(
bytes32 actionDomain,
bytes32 payloadDigest,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) private {
if (!registry.bootstrapSealed() && msg.sender == registry.bootstrapAdmin()) return;
registry.requireRegistrarQuorum(actionDomain, payloadDigest, anchorBlock, approvals);
}
/**
* @notice Set which role may write a tree and how many approvals it needs.
* @dev The configuration authority, never the tree's own quorum: a roster
* that could raise or lower its own threshold is a roster with no
* threshold. A tree left at `k == 0` refuses every quorum write with
* `TreeNotConfigured`, which is the state a fresh plane starts in.
* @param treeId The tree being configured.
* @param role Role a signer must hold for an approval to count.
* @param k Approvals a write needs; `0` leaves the tree unconfigured.
* @param anchorBlock The registrars' roster anchor. Ignored during bootstrap.
* @param approvals The sealed registrar quorum. Empty during bootstrap.
*/
function configureTree(
uint8 treeId,
uint256 role,
uint256 k,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_assertTree(treeId);
_requireConfigurationAuthority(
ACTION_CONFIGURE_TREE, keccak256(abi.encode(treeId, role, k)), anchorBlock, approvals
);
// Refuse a threshold nobody can meet. Register the members first; that
// ordering is the point, not an inconvenience. A 4-of-5 configured
// against three registered co-signers is a tree that reverts on every
// write, and the revert names the threshold rather than the roster.
if (k != 0) {
uint256 live = registry.liveMemberCount(role);
if (live < k) revert ThresholdUnreachable(treeId, live, k);
}
writerRole[treeId] = role;
threshold[treeId] = k;
emit TreeConfigured(treeId, role, k);
}
/**
* @notice Point a tree at the contract allowed to write it directly.
* @dev Same gate as `configureTree`, for the same reason. Setting it to the
* zero address removes the path entirely and leaves the tree quorum-only.
*
* Point this at a CONTRACT, never at an externally owned account. The whole
* argument for a quorum-free writer is that its rules are its bytecode; an
* account holding a key is exactly the single-key authority the quorum on
* {setLeaves} exists to prevent.
*
* Movable rather than immutable on purpose: an immutable pointer would mean
* a ledger redeploy abandons the tree it writes, with no way back.
* @param treeId The tree whose writer seat is being set.
* @param writer The contract admitted to it; zero removes the seat.
* @param anchorBlock The registrars' roster anchor. Ignored during bootstrap.
* @param approvals The sealed registrar quorum. Empty during bootstrap.
*/
function setTreeWriter(
uint8 treeId,
address writer,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_assertTree(treeId);
_requireConfigurationAuthority(
ACTION_SET_TREE_WRITER, keccak256(abi.encode(treeId, writer)), anchorBlock, approvals
);
treeWriter[treeId] = writer;
emit TreeWriterSet(treeId, writer);
}
/**
* @notice Point `syncIdentities` at the contract that knows the chain set.
* @dev Same gate as `setTreeWriter`. Zero removes the source, after which
* service leaves carry an empty `deployedChains` table — which is what a
* plane looks like before its asset registry is seeded, and is why this
* pointer belongs in the same bootstrap window as the seed itself.
* @param source The asset registry to read the enabled chain set from.
* @param anchorBlock The registrars' roster anchor. Ignored during bootstrap.
* @param approvals The sealed registrar quorum. Empty during bootstrap.
*/
function setChainSource(
address source,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireConfigurationAuthority(
ACTION_SET_CHAIN_SOURCE, keccak256(abi.encode(source)), anchorBlock, approvals
);
chainSource = source;
emit ChainSourceSet(source);
}
/// @notice Point tree 8's branch 3 at the slot-key registry it projects.
/// @dev Same gate as `setChainSource`. Zero closes the branch entirely:
/// {syncSlotKeyLeaves} reverts `SlotKeySourceUnset` rather than
/// writing leaves whose value nothing vouched for.
/// @param source The slot-key registry whose verdict the branch projects.
/// @param anchorBlock The registrars' roster anchor. Ignored during bootstrap.
/// @param approvals The sealed registrar quorum. Empty during bootstrap.
function setSlotKeySource(
address source,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireConfigurationAuthority(
ACTION_SET_SLOT_KEY_SOURCE, keccak256(abi.encode(source)), anchorBlock, approvals
);
slotKeySource = source;
emit SlotKeySourceSet(source);
}
/// @notice Point tree 8's branch 4 at the endpoint registry it projects.
/// @dev Same gate as `setSlotKeySource`, and the same fail-closed shape:
/// zero makes {syncEndpointLeaves} revert `EndpointSourceUnset`.
/// @param source The endpoint registry whose verdict the branch projects.
/// @param anchorBlock The registrars' roster anchor. Ignored during bootstrap.
/// @param approvals The sealed registrar quorum. Empty during bootstrap.
function setEndpointSource(
address source,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireConfigurationAuthority(
ACTION_SET_ENDPOINT_SOURCE, keccak256(abi.encode(source)), anchorBlock, approvals
);
endpointSource = source;
emit EndpointSourceSet(source);
}
/**
* @notice Adopt a preceding plane's counters — one `treeVersion` per tree
* (index = treeId, 0 unused) and the published `round` — so a
* redeploy stays monotonic for every consumer that compares them:
* rings, explorers, the round feed.
* @dev This contract is immutable, so replacing it means a new address, and
* a fresh address would otherwise restart every counter at zero. A consumer
* that treats a counter as monotonic would then read the new plane as
* older than the state it already holds, and quietly ignore live data.
*
* It carries the counters and nothing else. The roots behind those rounds
* stay with the plane that published them, so {roundRootAt} below the seed
* answers zero here — pin a round on the plane that produced it.
*
* Configuration authority (bootstrap admin before the seal, registrar
* quorum after), and only while this plane has published nothing:
* `NotFresh` otherwise, because rewinding a counter a consumer has already
* compared against is worse than never seeding at all.
* @param versions Per-tree write counters to adopt, indexed by tree id;
* index 0 is unused and must still be present.
* @param round_ The round number this plane continues from.
* @param anchorBlock The registrars' roster anchor. Ignored during bootstrap.
* @param approvals The sealed registrar quorum. Empty during bootstrap.
*/
function seedCounters(
uint64[] calldata versions,
uint64 round_,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireConfigurationAuthority(
ACTION_SEED_COUNTERS, keccak256(abi.encode(versions, round_)), anchorBlock, approvals
);
if (versions.length != TREE_COUNT + 1) revert VersionCountMismatch(versions.length);
if (round != 0) revert NotFresh();
for (uint8 t = 1; t <= TREE_COUNT; t++) {
if (treeVersion[t] != 0) revert NotFresh();
}
for (uint8 t = 1; t <= TREE_COUNT; t++) {
treeVersion[t] = versions[t];
}
round = round_;
emit CountersSeeded(round_, versions);
}
/// @notice Install the records contract that writes the typed trees.
/// @dev Trees 2, 3 and 4 have no other door at all — {setLeaves} refuses
/// them outright — so leaving this unset closes those three
/// completely. Same gate as `setTreeWriter`, and the same rule: a
/// contract, never an account holding a key.
/// @param writer The records contract admitted to {writeTyped}.
/// @param anchorBlock The registrars' roster anchor. Ignored during bootstrap.
/// @param approvals The sealed registrar quorum. Empty during bootstrap.
function setTypedWriter(
address writer,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_requireConfigurationAuthority(
ACTION_SET_TYPED_WRITER, keccak256(abi.encode(writer)), anchorBlock, approvals
);
typedWriter = writer;
emit TypedWriterSet(writer);
}
/**
* @notice Write configuration rows into a tree's branch 0.
* @param treeId The tree whose owning service the rows configure.
* @param keys `configKey(name, sub)` per row.
* @param values One word per row — a duration, a count, an address, a
* flag; the reader knows the shape from the name.
* @param anchorBlock The registrars' roster anchor. Ignored during bootstrap.
* @param approvals The sealed registrar quorum. Empty during bootstrap.
*
* @dev The configuration authority, not the tree's writer or quorum: a
* tree's writer states what its domain verified, its quorum attests to
* what it read, and neither is the authority over how the service that
* feeds it is configured.
*
* The value is stored beside the hash so a contract on this chain reads it
* in one call ({configValue}) while the same row is provable off chain
* against a round root. That is one source of truth for the fleet, the
* contracts and any explorer at once — a service reading its own
* environment instead would be a second source, free to disagree with this
* one and with nothing on chain able to notice.
*/
function setConfig(
uint8 treeId,
bytes32[] calldata keys,
bytes32[] calldata values,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_assertTree(treeId);
if (keys.length != values.length || keys.length == 0) revert LengthMismatch(keys.length, values.length);
_requireConfigurationAuthority(
ACTION_SET_CONFIG, keccak256(abi.encode(treeId, keys, values)), anchorBlock, approvals
);
for (uint256 i = 0; i < keys.length; i++) {
_configValue[treeId][keys[i]] = values[i];
_set(treeId, BRANCH_CONFIG, keys[i], configLeafHash(treeId, keys[i], values[i]));
emit ConfigSet(treeId, keys[i], values[i]);
}
_bump(treeId, keys.length);
}
// ------------------------------------------------------------- writing
/**
* @notice Write leaves into one branch of one tree under a PQ quorum.
* @param treeId Which tree.
* @param branch Which branch — never 0, which `setConfig` alone writes.
* @param keys Domain keys — a wallet address for accounts, an asset id for
* the allowlist, whatever identifies a row in that domain. Each gets
* a permanent slot in the branch on first write.
* @param leaves The raw (untagged) leaf values.
* @param anchorBlock The block the approving roster is read as of.
* @param approvals At least `threshold[treeId]` of them, ascending by signer.
*
* @dev The digest binds the tree, its nonce, and the full batch. Binding the
* nonce is what stops the same approved batch being replayed: without it,
* an approval to set a price is an approval to set that price again at any
* later block, which for an oracle is the whole attack.
*
* ML-DSA-87 is required rather than accepted. These are operational,
* high-cadence writes — the transaction class — and leaving the choice open
* would mean a break in either scheme takes the tree.
*
* Three tree classes are refused here outright, each with its own error:
* the typed trees (2, 3 and 4) because their preimage has to be built by
* the records contract, and the writer-only trees (7 and 8) because no set
* of service signatures can make a different answer true about an intent's
* status or an identity's standing.
*/
function setLeaves(
uint8 treeId,
uint8 branch,
bytes32[] calldata keys,
bytes32[] calldata leaves,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
_assertTree(treeId);
_assertDataBranch(treeId, branch);
if (treeId == TREE_PHI || treeId == TREE_VASSET || treeId == TREE_ORACLE || treeId == TREE_COMPLIANCE) {
revert TypedTreeOnly(treeId);
}
// Trees 7 and 8 have their own rulers and NO quorum path at all: an
// intent's status is what `FinalIntentLog` verified, an identity is
// what the registry or the ledger verified, and no set of service
// signatures can make a different answer true.
if (treeId == TREE_INTENTS || treeId == TREE_IDENTITY) revert WriterOnlyTree(treeId);
if (keys.length != leaves.length) revert LengthMismatch(keys.length, leaves.length);
uint256 k = threshold[treeId];
if (k == 0) revert TreeNotConfigured(treeId);
uint64 n = nonce[treeId];
FinalPqQuorum.require_(
registry,
approvals,
FinalPqQuorum.digest(
address(this),
ACTION_SET_LEAVES,
anchorBlock,
keccak256(abi.encode(treeId, branch, n, keys, leaves))
),
writerRole[treeId],
k,
FinalPqQuorum.ALG_ML_DSA_87,
anchorBlock,
false
);
nonce[treeId] = n + 1;
for (uint256 i = 0; i < keys.length; i++) {
_set(treeId, branch, keys[i], leaves[i]);
}
_bump(treeId, keys.length);
}
/// @notice One chain an account exists on, and as what.
/// @dev `chainRef` is the registry's CAIP-derived chain reference — the one
/// identifier that names an EVM chain and a non-EVM one alike — and
/// `account` is the wallet's account there, in that chain's own account
/// space (an EVM address right-aligned, a 32-byte key filling the
/// width). Field-for-field with `IWalletTypes.ChainAccount`.
struct ChainAccount {
/// @dev The registry's CAIP-derived reference for the chain.
bytes32 chainRef;
/// @dev The account on that chain, in that chain's own account space.
bytes32 account;
}
/// @notice `FinalWalletFactory.AccountStateLeaf`, field for field.
/// @dev The preimage of every tree-1 leaf. The field set, the field ORDER
/// and the domain must match the factory's exactly on every supported
/// chain; a field added, removed or reordered on one side alone is a
/// root every execution chain rejects with nothing naming the cause.
struct AccountStateLeaf {
/// @dev The Final Wallet this leaf describes. Also what `accountKeyFor`
/// hashes into the tree-1 key, so one wallet holds one slot.
address wallet;
/// @dev Active-stage access-key commitment — the credential the account
/// ledger checks a state transition against.
bytes32 liveAccess;
/// @dev Active-stage transaction-key commitment.
bytes32 liveTransaction;
/// @dev Pre-committed successor to `liveAccess`, so a rotation reveals a
/// key that was already committed rather than one chosen after.
bytes32 recoveryAccess;
/// @dev Pre-committed successor to `liveTransaction`.
bytes32 recoveryTransaction;
/// @dev Active-stage encapsulation commitment and its pre-committed
/// successor. Field-for-field with `FinalWalletFactory.AccountStateLeaf`;
/// a field added on one side and not the other is a root every execution
/// chain rejects, with nothing pointing at the cause.
bytes32 liveKem;
/// @dev Pre-committed successor to `liveKem`.
bytes32 recoveryKem;
/// @dev Who may authorize for this account. This is the PROVEN owner an
/// execution chain resolves authority from; a copy stored there is
/// wrong for as long as nobody has pushed to that chain, and
/// nothing there can tell.
address owner;
/// @dev Whether the account authorizes post-quantum. One-way once set.
bool pqEnabled;
/// @dev Whether the account is frozen. Returned to a resolver rather
/// than enforced by it, so a reader can still learn who owns a
/// frozen account; the wallet refuses on this PROVEN value rather
/// than on a synced copy, so a chain behind on the fan-out cannot
/// let a frozen account transact.
bool frozen;
/// @dev The chains this account exists on, and its account on each —
/// including chains whose accounts are not EVM addresses. Decided HERE
/// (set by the holder through the ledger) and enforced there: an
/// execution chain refuses to create the account unless the table has a
/// row for it, and a settlement toward a chain with no row is refused at
/// the source. This is also what a zero beneficiary resolves through: a
/// table naming the account on each chain answers "as what", which a
/// bare membership flag never could. `_assertChainAccounts` rejects a
/// zero chain, a zero account and a repeated chain, so no door can
/// publish a table a resolver would read two ways.
ChainAccount[] deployedChains;
/// @dev Per-chain dormancy verdict, one bit per asset-registry chain
/// slot, so the bit positions are the registry's slot numbering rather
/// than this table's row order.
uint32 dormantChains;
/// @dev Monotonic per-account revision. Lets a reader holding two
/// proofs tell which one is newer without consulting a round.
uint64 version;
}
/**
* @notice Write account state into tree 1 from the typed leaf.
* @dev The typed form exists so the leaf preimage is built HERE rather than
* by whoever assembles the calldata. Tree 1 is the source of truth for every
* other chain, and `syncAccountState` will accept any 32 bytes that carry a
* valid proof — so if the publisher chose the preimage, the publisher could
* write an account state that no wallet record on this chain agrees with,
* and the proof would still verify everywhere.
*
* **Sealed.** Tree 1 is membership: a leaf here is who an account is, on
* every chain. So the round takes the hybrid class — each approval carries
* the ML-DSA-87 vote AND the member's SLH-DSA seal — where the other trees
* take the transaction class alone. A lattice break rewrites a price; it
* does not rewrite an account.
* @param leaves The account states to write, one per wallet.
* @param anchorBlock The block the approving roster is read as of.
* @param approvals At least `threshold[TREE_ACCOUNTS]` of them, ascending by signer.
*/
function setAccountStates(
AccountStateLeaf[] calldata leaves,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
uint256 k = threshold[TREE_ACCOUNTS];
if (k == 0) revert TreeNotConfigured(TREE_ACCOUNTS);
bytes32[] memory keys = new bytes32[](leaves.length);
bytes32[] memory hashes = new bytes32[](leaves.length);
for (uint256 i = 0; i < leaves.length; i++) {
keys[i] = accountKeyFor(leaves[i].wallet);
hashes[i] = accountStateLeafHash(leaves[i]);
}
uint64 n = nonce[TREE_ACCOUNTS];
FinalPqQuorum.require_(
registry,
approvals,
FinalPqQuorum.digest(
address(this),
ACTION_SET_LEAVES,
anchorBlock,
keccak256(abi.encode(TREE_ACCOUNTS, n, keys, hashes))
),
writerRole[TREE_ACCOUNTS],
k,
FinalPqQuorum.ALG_ML_DSA_87,
anchorBlock,
true
);
nonce[TREE_ACCOUNTS] = n + 1;
for (uint256 i = 0; i < leaves.length; i++) {
_set(TREE_ACCOUNTS, BRANCH_MAIN, keys[i], hashes[i]);
}
_bump(TREE_ACCOUNTS, leaves.length);
}
/**
* @notice Write account state into tree 1 from the contract that owns it.
* @dev No quorum, and no nonce burned: `treeWriter[1]` is the ledger, and
* the ledger already verified the holder's own signature before it called
* here. See {treeWriter} for why adding a service quorum on top would be a
* censorship power rather than a safeguard.
*
* Typed, exactly as `setAccountStates` is: the preimage is built HERE, so
* even the writer contract cannot publish a leaf whose meaning no record on
* this chain agrees with.
* @param leaves The account states to write, one per wallet.
*/
function setAccountStatesAsWriter(AccountStateLeaf[] calldata leaves) external {
if (msg.sender != treeWriter[TREE_ACCOUNTS]) revert NotAuthorized(msg.sender);
for (uint256 i = 0; i < leaves.length; i++) {
_set(TREE_ACCOUNTS, BRANCH_MAIN, accountKeyFor(leaves[i].wallet), accountStateLeafHash(leaves[i]));
}
_bump(TREE_ACCOUNTS, leaves.length);
}
/**
* @notice Write raw leaves into any tree from the contract that owns it.
* @dev The generic sibling of {setAccountStatesAsWriter}, for a tree whose
* writer is a contract rather than a service quorum. Same authorization —
* `treeWriter[treeId]` and nothing else — and the same reasoning: the
* writer has already verified whatever its domain requires, and layering a
* quorum on top of a contract's own rules is a censorship power rather
* than a safeguard.
*
* UNTYPED, unlike the account path, and that is the trade. Tree 1's
* preimage is built here so even the ledger cannot publish a leaf whose
* meaning no record agrees with; a generic writer supplies its own hash,
* so the leaf means whatever that contract says it means. Acceptable only
* because the writer is a specific contract this chain's operators
* installed — its rules are its bytecode, it has no owner and no proxy —
* and NOT acceptable for a role-gated key. Point `treeWriter` at a
* contract, never at an externally owned account.
* @param treeId The tree to write.
* @param branch The branch within it. Never 0, which `setConfig` alone writes.
* @param keys Domain keys, one per leaf. Each takes a permanent slot in the
* branch on first write.
* @param leaves The raw (untagged) leaf values.
*/
function setLeavesAsWriter(uint8 treeId, uint8 branch, bytes32[] calldata keys, bytes32[] calldata leaves)
external
{
if (msg.sender != treeWriter[treeId]) revert NotAuthorized(msg.sender);
_assertDataBranch(treeId, branch);
if (keys.length != leaves.length) revert LengthMismatch(keys.length, leaves.length);
for (uint256 i = 0; i < keys.length; i++) {
_set(treeId, branch, keys[i], leaves[i]);
}
_bump(treeId, keys.length);
}
/// @notice The leaf hash `FinalWalletFactory.accountStateLeafHash` computes.
/// @dev Identical `abi.encode`, identical field order, identical domain, and
/// that identity is the whole contract between this chain and every
/// execution chain. `deployedChains` rides through `abi.encode` like every
/// other field — head offset, then length and rows — so the table is
/// committed whole and in order. The table is validated here rather than at
/// each door, so every path into tree 1 gets the same refusal.
/// @param leaf The account state to commit to.
/// @return The tagged leaf hash, ready to be placed in tree 1.
function accountStateLeafHash(AccountStateLeaf memory leaf) public pure returns (bytes32) {
_assertChainAccounts(leaf.deployedChains);
return keccak256(
abi.encode(
DOMAIN_ACCOUNT_STATE_LEAF,
leaf.wallet,
leaf.liveAccess,
leaf.liveTransaction,
leaf.recoveryAccess,
leaf.recoveryTransaction,
leaf.liveKem,
leaf.recoveryKem,
leaf.owner,
leaf.pqEnabled,
leaf.frozen,
leaf.deployedChains,
leaf.dormantChains,
leaf.version
)
);
}
/// @notice Reject a `deployedChains` table a resolver could not read.
/// @dev A well-formed table: no zero chain, no zero account, no chain twice.
/// Checked where the leaf is hashed so no door — quorum, writer
/// contract, identity projection — can publish a table a resolver
/// would read two ways. The duplicate scan is quadratic in the row
/// count, which is deliberate: gas is not a constraint on this chain,
/// and a sort or a seen-set would cost correctness or storage to save
/// something nobody is paying for.
/// @param rows The table to validate.
function _assertChainAccounts(ChainAccount[] memory rows) private pure {
for (uint256 i = 0; i < rows.length; i++) {
if (rows[i].chainRef == bytes32(0) || rows[i].account == bytes32(0)) {
revert InvalidChainAccount(rows[i].chainRef, rows[i].account);
}
for (uint256 j = 0; j < i; j++) {
if (rows[j].chainRef == rows[i].chainRef) {
revert InvalidChainAccount(rows[i].chainRef, rows[i].account);
}
}
}
}
/// @notice The account `wallet`'s published table names on `chainRef`, or
/// zero if it has no row there.
/// @dev A convenience over `accountStateLeafHash`'s input for readers on
/// this chain; execution chains answer the same question from their synced
/// record (`FinalWalletFactory.addressOn`). Pure, so it reads the leaf it is
/// handed and never this contract's storage — the caller is responsible for
/// having proved that leaf first.
/// @param leaf The account state to search.
/// @param chainRef The chain being asked about.
/// @return The account on that chain, or zero when the table has no row for it.
function accountOn(AccountStateLeaf memory leaf, bytes32 chainRef) public pure returns (bytes32) {
for (uint256 i = 0; i < leaf.deployedChains.length; i++) {
if (leaf.deployedChains[i].chainRef == chainRef) return leaf.deployedChains[i].account;
}
return bytes32(0);
}
/**
* @notice The typed trees' write door — `FinalStateRecords` alone.
* @dev The quorum, the nonce and the write, shared by every typed record.
* The records contract computed the keys and hashes from the structs it
* stores; this contract admits nobody else to trees 2, 3 and 4
* (`setLeaves` refuses them), so the value there can never drift from
* the commitment here.
*
* The digest is byte-identical to `setLeaves`' over the same keys and
* hashes, deliberately: the typed entrypoints choose the PREIMAGE, not the
* authorization. A member recomputes one digest whichever door the batch
* came through, and there is no second approval shape to get wrong.
*
* Always branch 1: a typed record is a domain row, and branch 0 belongs to
* the configuration authority on every tree without exception.
* @param treeId The typed tree being written.
* @param keys Domain keys the records contract computed, one per leaf.
* @param hashes Leaf hashes the records contract computed from its structs.
* @param anchorBlock The block the approving roster is read as of.
* @param approvals At least `threshold[treeId]` of them, ascending by signer.
*/
function writeTyped(
uint8 treeId,
bytes32[] memory keys,
bytes32[] memory hashes,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
if (msg.sender != typedWriter) revert NotAuthorized(msg.sender);
uint256 k = threshold[treeId];
if (k == 0) revert TreeNotConfigured(treeId);
uint64 n = nonce[treeId];
FinalPqQuorum.require_(
registry,
approvals,
FinalPqQuorum.digest(
address(this),
ACTION_SET_LEAVES,
anchorBlock,
keccak256(abi.encode(treeId, n, keys, hashes))
),
writerRole[treeId],
k,
FinalPqQuorum.ALG_ML_DSA_87,
anchorBlock,
false
);
nonce[treeId] = n + 1;
for (uint256 i = 0; i < keys.length; i++) {
_set(treeId, BRANCH_MAIN, keys[i], hashes[i]);
}
_bump(treeId, keys.length);
}
/**
* @notice The typed door for a tree whose leaves live in SEVERAL data branches — tree 9, whose
* approvals, revocations, counters and attestations are four key families, each with a
* permanent branch. Same writer, same role, same threshold and the same per-tree nonce as
* `writeTyped`; the branch is folded into the signed payload so a quorum that approved a
* revocation cannot be replayed as an approval.
* @dev `writeTyped` stays byte-for-byte what it is (trees 2–4 write `BRANCH_MAIN` and their lanes
* sign `(treeId, n, keys, hashes)`); this door signs `(treeId, branch, n, keys, hashes)`.
* Branch 0 is `setConfig`'s alone.
* @param treeId The tree.
* @param branch The data branch every key of this write lives in (`1 .. BRANCH_COUNT - 1`).
* @param keys Domain keys, as the companion derived them.
* @param hashes The leaf hashes, one per key.
* @param anchorBlock The roster anchor the approvals were made against.
* @param approvals `threshold[treeId]` ML-DSA-87 votes from `writerRole[treeId]` members.
*/
function writeTypedInBranch(
uint8 treeId,
uint8 branch,
bytes32[] memory keys,
bytes32[] memory hashes,
uint64 anchorBlock,
FinalPqQuorum.Approval[] calldata approvals
) external {
if (msg.sender != typedWriter) revert NotAuthorized(msg.sender);
_assertDataBranch(treeId, branch);
if (keys.length != hashes.length) revert LengthMismatch(keys.length, hashes.length);
uint256 k = threshold[treeId];
if (k == 0) revert TreeNotConfigured(treeId);
uint64 n = nonce[treeId];
FinalPqQuorum.require_(
registry,
approvals,
FinalPqQuorum.digest(
address(this),
ACTION_SET_LEAVES,
anchorBlock,
keccak256(abi.encode(treeId, branch, n, keys, hashes))
),
writerRole[treeId],
k,
FinalPqQuorum.ALG_ML_DSA_87,
anchorBlock,
false
);
nonce[treeId] = n + 1;
for (uint256 i = 0; i < keys.length; i++) {
_set(treeId, branch, keys[i], hashes[i]);
}
_bump(treeId, keys.length);
}
/**
* @notice Snapshot every tree's root into a new round.
* @dev Permissionless, deliberately. Every root being snapshotted was
* already authorized by its tree's quorum, so this adds no authority — it
* only fixes a moment. Requiring a signature would put a liveness
* dependency in front of publication for no security gain.
*
* A round that would change nothing is refused, so the round number cannot
* be advanced by anyone with gas to spend.
* @return published The round number just written.
*/
function publishRound() external returns (uint64 published) {
bool changed;
for (uint8 t = 1; t <= TREE_COUNT; t++) {
if (treeVersion[t] != _publishedVersion[t]) {
changed = true;
break;
}
}
if (!changed) revert NothingToPublish();
published = round + 1;
Round storage r = _rounds[published];
for (uint8 t = 1; t <= TREE_COUNT; t++) {
r.roots[t] = liveRoot[t];
_publishedVersion[t] = treeVersion[t];
}
r.roundRoot = _foldForest(_forestLeaves(r.roots));
r.blockNumber = uint64(block.number);
// MILLISECONDS, like every instant on this chain.
r.timestamp = FinalChainTime.nowMs();
round = published;
emit RoundPublished(published, r.blockNumber, r.timestamp);
}
// ---------------------------------------------------------------- views
/// @notice Every root from one round. Index by the `TREE_*` constants;
/// index 0 is unused.
/// @dev An unpublished round answers all zeros rather than reverting, so a
/// caller scanning forward can tell where the history ends.
/// @param which The round number.
/// @return The eight tree roots at that round, indexed by tree id.
function rootsAt(uint64 which) external view returns (bytes32[TREE_COUNT + 1] memory) {
return _rounds[which].roots;
}
/// @notice One tree's root at one round.
/// @param which The round number.
/// @param treeId The tree to read.
/// @return That tree's root at that round; zero if the round is unpublished.
function rootAt(uint64 which, uint8 treeId) external view returns (bytes32) {
_assertTree(treeId);
return _rounds[which].roots[treeId];
}
/// @notice The one word that commits to every tree at one round.
/// @dev The value a consumer pins. Everything in the plane at that instant
/// proves against it, which is the only contemporaneity this contract
/// offers — the live roots move independently and do not.
/// @param which The round number.
/// @return The round root; zero if the round is unpublished on this plane.
function roundRootAt(uint64 which) external view returns (bytes32) {
return _rounds[which].roundRoot;
}
/**
* @notice The `FOREST_BITS` siblings that take a tree's root at one round
* up to that round's root — appended to `proofFor`, they make a
* leaf provable against `roundRootAt(which)` by the same verifier.
* @dev Folds the round's stored roots in memory rather than keeping the
* upper levels in storage: the fold is cheap, and one stored copy of a
* value is one fewer place for two copies to disagree.
* @param which The round number. Must be published on this plane.
* @param treeId The tree whose root is being lifted to the round root.
* @return path The `FOREST_BITS` siblings, lowest level first.
*/
function roundProofFor(uint64 which, uint8 treeId) external view returns (bytes32[] memory path) {
_assertTree(treeId);
if (which == 0 || which > round) revert NoRounds();
bytes32[] memory level = _forestLeaves(_rounds[which].roots);
path = new bytes32[](FOREST_BITS);
uint256 idx = treeId;
uint256 n = level.length;
for (uint256 l = 0; l < FOREST_BITS; l++) {
path[l] = level[idx ^ 1];
n >>= 1;
for (uint256 i = 0; i < n; i++) {
level[i] = _pair(level[2 * i], level[2 * i + 1]);
}
idx >>= 1;
}
}
/// @notice The latest round's roots, with the block it was taken at.
/// @dev Reverts `NoRounds` on a plane that has published nothing, rather
/// than answering an empty round that a caller could mistake for a
/// real snapshot of an empty plane.
/// @return which The round number.
/// @return roots The eight tree roots, indexed by tree id; index 0 unused.
/// @return blockNumber Block the snapshot was taken in.
/// @return timestamp Snapshot instant, in milliseconds.
function latestRound()
external
view
returns (uint64 which, bytes32[TREE_COUNT + 1] memory roots, uint64 blockNumber, uint64 timestamp)
{
which = round;
if (which == 0) revert NoRounds();
Round storage r = _rounds[which];
return (which, r.roots, r.blockNumber, r.timestamp);
}
/// @notice The raw leaf stored for a key, and whether it has a slot.
/// @dev The UNTAGGED value, as it was written. The tag is applied when the
/// leaf is hashed into the tree, so a caller reproducing a leaf hash
/// applies it themselves. A key with no slot answers `(0, false)`
/// rather than reverting, so presence is a question this view can be
/// asked directly.
/// @param treeId The tree to read.
/// @param key The domain key.
/// @return leaf The stored value, or zero when the key has no slot.
/// @return present Whether the key holds a slot in this tree.
function leafOf(uint8 treeId, bytes32 key) external view returns (bytes32 leaf, bool present) {
uint256 s = _slotPlusOne[treeId][key];
if (s == 0) return (bytes32(0), false);
return (_leaf[treeId][s - 1], true);
}
/// @notice The permanent slot for a key. Reverts if it has none. The
/// slot's top `BRANCH_BITS` are its branch.
/// @dev Stored one-based internally so an unassigned key is distinguishable
/// from slot 0, and returned zero-based here — slot 0 of branch 0 is a
/// real position.
/// @param treeId The tree to read.
/// @param key The domain key.
/// @return The key's zero-based slot index within the tree.
function slotOf(uint8 treeId, bytes32 key) public view returns (uint256) {
uint256 s = _slotPlusOne[treeId][key];
if (s == 0) revert UnknownKey(treeId, key);
return s - 1;
}
/// @notice The key a slot was handed to, or zero if it is still free —
/// the enumeration every branch offers: slots `branch << BRANCH_DEPTH`
/// through `+ branchSlotsUsed(treeId, branch) - 1`.
/// @dev Because slots are handed out in order and never reused, that range
/// is exactly the branch's contents: a reader enumerates a branch on
/// chain without an event window and without an indexer.
/// @param treeId The tree to read.
/// @param slot The slot index.
/// @return The key holding that slot, or zero when it was never handed out.
function keyAt(uint8 treeId, uint256 slot) external view returns (bytes32) {
return _keyAt[treeId][slot];
}
/// @notice Slots handed out in one branch.
/// @param treeId The tree to read.
/// @param branch The branch to read.
/// @return How many slots of that branch are in use — its enumeration bound.
function branchSlotsUsed(uint8 treeId, uint8 branch) external view returns (uint256) {
return _branchSlotsUsed[treeId][branch];
}
/// @notice One branch's root: the level-`BRANCH_DEPTH` node at its position.
/// @dev A branch that has never been written answers the empty-subtree hash
/// at that level, not zero, because that is genuinely its root.
/// @param treeId The tree the branch belongs to.
/// @param branch The branch to read.
/// @return The branch's root node.
function branchRoot(uint8 treeId, uint8 branch) external view returns (bytes32) {
_assertTree(treeId);
_assertBranch(branch);
return _nodeAt(treeId, BRANCH_DEPTH, branch);
}
/// @notice The first `BRANCH_DEPTH` siblings of `proofFor` — a proof
/// against the leaf's branch root rather than the tree root.
/// @dev The same path cut lower. A consumer that only ever needs one
/// branch can pin `branchRoot` and verify with fewer siblings; the
/// verifier is unchanged, since sorted pairs carry no direction bits.
/// @param treeId The tree to read.
/// @param key The domain key. Must already hold a slot.
/// @return The sibling path from the leaf up to its branch root.
function branchProofFor(uint8 treeId, bytes32 key) external view returns (bytes32[] memory) {
_assertTree(treeId);
return _path(treeId, slotOf(treeId, key), BRANCH_DEPTH);
}
/// @notice A configuration row's value, and whether the row exists.
/// @dev Presence is read from the slot table, not from the value: a row
/// deliberately set to zero exists and answers `present`.
/// @param treeId The tree whose branch 0 holds the row.
/// @param key The row key, as {configKey} computes it.
/// @return value The row's single word of value.
/// @return present Whether the row has ever been written.
function configValue(uint8 treeId, bytes32 key) external view returns (bytes32 value, bool present) {
present = _slotPlusOne[treeId][key] != 0;
value = _configValue[treeId][key];
}
/// @notice The branch-0 key of a configuration row: a name the owning
/// service defines, and a sub-key (a chain reference, an asset, zero).
/// @dev Its own key domain, so a configuration row can never be handed a
/// slot that a domain row of the same tree would want.
/// @param name The row's name, defined by the service that owns the tree.
/// @param sub The row's sub-key, or zero when the name stands alone.
/// @return The branch-0 key.
function configKey(bytes32 name, bytes32 sub) public pure returns (bytes32) {
return keccak256(abi.encode(DOMAIN_CONFIG_KEY, name, sub));
}
/// @notice The leaf a configuration row hashes to.
/// @dev Binds the tree id as well as the key and the value, so the same row
/// in two trees is two different leaves and a proof cannot be carried
/// from one tree's branch 0 to another's.
/// @param treeId The tree the row belongs to.
/// @param key The row key.
/// @param value The row value.
/// @return The untagged leaf value for that row.
function configLeafHash(uint8 treeId, bytes32 key, bytes32 value) public pure returns (bytes32) {
return keccak256(abi.encode(DOMAIN_CONFIG_LEAF, treeId, key, value));
}
/// @notice The tree-8 branch-2 key an owner occupies.
/// @param owner The owner whose wallet list the row indexes.
/// @return The branch-2 key.
function ownerIndexKeyFor(address owner) public pure returns (bytes32) {
return keccak256(abi.encode(DOMAIN_OWNER_INDEX_KEY, owner));
}
/// @notice The owner-index leaf: a commitment to the ledger's ordered
/// `walletsByOwner(owner)`.
/// @dev A commitment, not the list. The tree is the search structure; the
/// ledger holds the readable array this leaf proves, so ORDER matters
/// — the same wallets in a different order are a different leaf.
/// @param owner The owner the index row belongs to.
/// @param wallets The owner's wallets, in the ledger's own order.
/// @return The untagged leaf value for that row.
function ownerIndexLeafHash(address owner, address[] memory wallets) public pure returns (bytes32) {
return keccak256(abi.encode(DOMAIN_OWNER_INDEX_LEAF, owner, wallets));
}
/// @notice The tree-8 branch-3 key of one member's slot — a ring position.
/// @dev The index is reduced modulo `SLOT_KEY_RING` here, so the branch is
/// an index over the recent slots and never fills. A caller passes the
/// real slot number and does not do the reduction itself.
/// @param member The co-signer the slot key belongs to.
/// @param slotIndex The slot number, before the ring modulus.
/// @return The branch-3 key.
function slotKeyFor(address member, uint64 slotIndex) public pure returns (bytes32) {
return keccak256(abi.encode(DOMAIN_SLOT_KEY, member, slotIndex % SLOT_KEY_RING));
}
/**
* @notice Project slot keys into tree 8's branch 3 — the co-signers'
* per-slot KEM publics the private option seals to.
* @dev Permissionless, for {syncIdentityLeaves}' reason: the leaf VALUE
* is `slotKeySource`'s own verdict (the registry verified the member's
* signature when the key was published, and answers zero once the slot's
* window has passed), so this adds no authority and only projects. The
* registry calls it same-tx on publication; anyone may call it to retire a
* slot that lapsed by time.
* @param member The co-signer whose ring positions are being projected.
* @param slotIndexes The slots to project. Reduced modulo `SLOT_KEY_RING`.
*/
function syncSlotKeyLeaves(address member, uint64[] calldata slotIndexes) external {
address source = slotKeySource;
if (source == address(0)) revert SlotKeySourceUnset();
for (uint256 i = 0; i < slotIndexes.length; i++) {
_set(
TREE_IDENTITY,
BRANCH_SLOT_KEYS,
slotKeyFor(member, slotIndexes[i]),
ISlotKeySource(source).slotKeyLeafOf(member, slotIndexes[i])
);
}
_bump(TREE_IDENTITY, slotIndexes.length);
}
/// @notice The tree-8 branch-4 key of one tunnel endpoint.
/// @param endpointId The endpoint's certificate subject key id.
/// @return The branch-4 key.
function endpointKeyFor(bytes32 endpointId) public pure returns (bytes32) {
return keccak256(abi.encode(DOMAIN_ENDPOINT_KEY, endpointId));
}
/**
* @notice Project tunnel endpoints into tree 8's branch 4.
* @dev Permissionless, for {syncSlotKeyLeaves}' reason: the leaf VALUE is
* `endpointSource`'s own verdict — the registry admitted the certificate
* under the registrar quorum with the holder's proof of possession, and
* answers the revoked status once it is revoked — so this adds no authority
* and only projects. The registry calls it same-tx on registration and
* revocation; anyone may call it to re-project.
* @param endpointIds The endpoint ids to project.
*/
function syncEndpointLeaves(bytes32[] calldata endpointIds) external {
address source = endpointSource;
if (source == address(0)) revert EndpointSourceUnset();
for (uint256 i = 0; i < endpointIds.length; i++) {
_set(
TREE_IDENTITY,
BRANCH_ENDPOINTS,
endpointKeyFor(endpointIds[i]),
IEndpointSource(source).endpointLeafOf(endpointIds[i])
);
}
_bump(TREE_IDENTITY, endpointIds.length);
}
/**
* @notice The sibling path for a key, ready for
* `FinalMerkle.verifyTaggedSortedProof` on any chain.
* @dev The sanctioned way to ask any tree a question, tree 1 above all: a
* view, so a caller fetches a proof with one `eth_call` and never rebuilds
* the tree off chain. Rebuilding is where a divergence between what the
* chain holds and what a service believes it holds would come from, and
* this removes the second implementation entirely.
*
* A rebuild is not merely redundant, it is wrong. This tree is fixed depth,
* zero-padded and insertion-ordered; a fold that sorts its leaves or sizes
* itself to the leaf count produces a different root, and a proof against
* that root verifies nowhere while looking perfectly well formed.
*
* Pair the path with {liveRoot} for the current root, or append
* {roundProofFor} and verify against {roundRootAt} to pin a whole round.
* @param treeId The tree to read.
* @param key The domain key. Must already hold a slot.
* @return The `DEPTH` siblings from the leaf up to the tree root, lowest first.
*/
function proofFor(uint8 treeId, bytes32 key) external view returns (bytes32[] memory) {
_assertTree(treeId);
return _path(treeId, slotOf(treeId, key), DEPTH);
}
/// @notice The empty-subtree hash at a level. Level `DEPTH` is the root of
/// a tree with nothing in it.
/// @dev What an off-chain verifier needs to reproduce the padding this tree
/// uses. Levels run `0 .. ROUND_DEPTH`; anything above reverts on the
/// array bound.
/// @param level The level to read.
/// @return The hash of an empty subtree of that height.
function emptyRoot(uint256 level) external view returns (bytes32) {
return _zero[level];
}
/// @notice The tree-1 key a wallet occupies.
/// @dev A full-width hash rather than the packed address, so a hashed key
/// cannot be steered onto a slot an address key would take.
/// @param wallet The Final Wallet.
/// @return The tree-1 key.
function accountKeyFor(address wallet) public pure returns (bytes32) {
return keccak256(abi.encode(DOMAIN_ACCOUNT_KEY, wallet));
}
/**
* @notice Copy a registered identity into tree 1 as an account-state leaf.
* @dev Services are Final Wallets, so a service's leaf is the SAME leaf a
* user's wallet gets — `FinalWalletFactory.AccountStateLeaf`, four key
* commitments and all. There is no second shape and no second domain,
* which is what lets every chain that already consumes account state
* consume a co-signer's identity with no contract change.
*
* `owner` is the account itself: a service wallet is its own owner, having
* no separate holder to speak for it.
*
* Permissionless, and for the same reason `publishRound` is: every fact it
* writes was already authorized when it entered the registry, so this adds
* no authority and only projects. Gating it would put a liveness dependency
* in front of publishing a revocation, which is the one thing that must
* never wait.
* @param accounts The registered service identities to project. Each must
* already be registered; an unknown account reverts `UnknownKey`.
*/
function syncIdentities(address[] calldata accounts) external {
// One table for the batch: a service is its own canonical address on
// every enabled chain, so the rows differ only in `account`.
bytes32[] memory chainRefs = _enabledChainRefs();
for (uint256 i = 0; i < accounts.length; i++) {
address who = accounts[i];
FinalIdentityRegistry.Identity memory id = registry.identityOf(who);
if (!id.registered) revert UnknownKey(TREE_ACCOUNTS, accountKeyFor(who));
(bytes32 la, bytes32 lt, bytes32 ra, bytes32 rt) = registry.keyCommitments(who);
(bytes32 lk, bytes32 rk) = registry.kemCommitments(who);
ChainAccount[] memory table = new ChainAccount[](chainRefs.length);
for (uint256 c = 0; c < chainRefs.length; c++) {
table[c] = ChainAccount({chainRef: chainRefs[c], account: bytes32(uint256(uint160(who)))});
}
AccountStateLeaf memory leaf = AccountStateLeaf({
wallet: who,
liveAccess: la,
liveTransaction: lt,
recoveryAccess: ra,
recoveryTransaction: rt,
liveKem: lk,
recoveryKem: rk,
// A service reaches every chain the registry has enabled, at
// its own address, and is never dormant: dormancy measures an
// ABSENT holder, and these identities have no holder to be
// absent.
deployedChains: table,
dormantChains: 0,
owner: who,
// Every identity here is PQ by construction — there is no other
// kind of key in this registry.
pqEnabled: true,
// Revocation is a leaf that CHANGES, not one that disappears.
// A consumer holding an old proof gets a stale `false`, which is
// why the round is the thing to pin.
frozen: id.revoked,
version: id.version
});
_set(TREE_ACCOUNTS, BRANCH_MAIN, accountKeyFor(who), accountStateLeafHash(leaf));
}
_bump(TREE_ACCOUNTS, accounts.length);
}
/// @notice The tree-8 slot key an identity occupies.
/// @dev Its own domain, separate from the tree-1 account key, so one
/// account's admission row and its state row can never collide.
/// @param account The identity.
/// @return The tree-8 branch-1 key.
function identityKeyFor(address account) public pure returns (bytes32) {
return keccak256(abi.encode(DOMAIN_IDENTITY_TREE_KEY, account));
}
/**
* @notice Project identities into tree 8 — the wallet-creation admission
* set whose live root every execution chain anchors as its
* `currentIdentityRoot`.
*
* @dev The leaf VALUE is the registry's own verdict —
* `FinalIdentityRegistry.identityTreeLeafOf`: the execution chains'
* identity leaf while the identity stands, zero once it does not. Derived
* there rather than here because every input (serial, the six key
* commitments, standing, the CA depth pair) is registry storage, and this
* contract sits against EIP-170 while the registry does not.
*
* Permissionless, for exactly {syncIdentities}' reason: every fact
* written here was authorized when it entered the registry, so this adds
* no authority and only projects. The registry itself calls it same-tx on
* every identity mutation (register, rotate, roles, revoke, LMS-key ops),
* which is what makes the root CONTINUOUS; the open door additionally lets
* anyone retire a leaf whose standing lapsed by TIME — expiry moves no
* registry storage, so no mutation hook can ever fire for it.
*
* There is no quorum door and no writer seat (both raw doors refuse this
* tree), so the strongest thing any caller can do here is copy the
* registry's own verdict.
* @param accounts The identities to project. An unregistered account
* projects the registry's zero verdict, which retires its leaf.
*/
function syncIdentityLeaves(address[] calldata accounts) external {
for (uint256 i = 0; i < accounts.length; i++) {
_set(TREE_IDENTITY, BRANCH_MAIN, identityKeyFor(accounts[i]), registry.identityTreeLeafOf(accounts[i]));
}
_bump(TREE_IDENTITY, accounts.length);
}
/**
* @notice Per-tree quorum health: can each configured tree still be written?
* @dev A threshold above the live member count is not a strict quorum, it is
* a tree that reverts forever with nothing naming the roster as the cause.
* `configureTree` refuses to create that state, but revocation can arrive at
* it later — revocation must never be blocked on quorum arithmetic, so the
* check has to be something monitoring reads rather than something the
* contract enforces after the fact.
* @return live Members currently holding each tree's writer role; zero for
* an unconfigured tree, which is not the same as a starved one.
* @return required Each tree's threshold, indexed by tree id.
* @return ok Whether each tree can still be written. An unconfigured tree
* reports `true`: it is closed, not starved.
*/
function quorumHealth()
external
view
returns (uint256[] memory live, uint256[] memory required, bool[] memory ok)
{
live = new uint256[](TREE_COUNT + 1);
required = new uint256[](TREE_COUNT + 1);
ok = new bool[](TREE_COUNT + 1);
for (uint8 t = 1; t <= TREE_COUNT; t++) {
required[t] = threshold[t];
live[t] = required[t] == 0 ? 0 : registry.liveMemberCount(writerRole[t]);
ok[t] = required[t] == 0 || live[t] >= required[t];
}
}
// -------------------------------------------------------------- internal
/// @notice The chain set a service account's `deployedChains` table is built from.
/// @dev The enabled chain references `chainSource` knows, or none if it is
/// unset. Read through the narrow interface so this contract need not
/// import the registry that imports it. An unset source answers an
/// empty list rather than reverting, because a plane whose registry is
/// not yet seeded must still be able to project its identities.
/// @return The enabled chain references, or an empty list when unset.
function _enabledChainRefs() private view returns (bytes32[] memory) {
address source = chainSource;
if (source == address(0)) return new bytes32[](0);
return IChainSource(source).enabledChainRefs();
}
/// @notice Refuse a tree id outside `1 .. TREE_COUNT`.
/// @dev Trees are 1-indexed so a tree id doubles as its position in the
/// round tree; id 0 is the unused position there and not a tree here.
/// @param treeId The id to check.
function _assertTree(uint8 treeId) private pure {
if (treeId == 0 || treeId > TREE_COUNT) revert UnknownTree(treeId);
}
/// @notice Refuse a branch id no slot can encode.
/// @dev The bound is the branch COUNT, not the count of branches in use: an
/// unused branch is a legal, empty subtree.
/// @param branch The id to check.
function _assertBranch(uint8 branch) private pure {
if (branch >= BRANCH_COUNT) revert UnknownBranch(branch);
}
/// @notice Refuse a branch a quorum or a writer contract may not write.
/// @dev A branch a quorum or a writer may write: any but the config branch.
/// Branch 0 belongs to the configuration authority on every tree, so
/// the refusal is structural rather than per-tree.
/// @param treeId The tree, carried so the revert names it.
/// @param branch The branch being written.
function _assertDataBranch(uint8 treeId, uint8 branch) private pure {
_assertBranch(branch);
if (branch == BRANCH_CONFIG) revert ConfigBranchReserved(treeId);
}
/// @notice Advance a tree's write counter and announce the new root.
/// @dev Version + event, the tail of every write door. Called AFTER the
/// leaves have settled, so the event carries the root a reader will
/// see, and the counter is what {publishRound} compares to decide
/// whether a round would carry anything new.
/// @param treeId The tree that moved.
/// @param count Leaves in the batch, for the event.
function _bump(uint8 treeId, uint256 count) private {
uint64 v = treeVersion[treeId] + 1;
treeVersion[treeId] = v;
emit LeavesSet(treeId, count, liveRoot[treeId], v);
}
/// @notice The one internal-node hash every tree, branch and round shares.
/// @dev `keccak256(0x01 ‖ lo ‖ hi)`, the pair sorted — the one node hash.
/// Sorting is what makes a proof position-agnostic, so it carries no
/// direction bits; the 0x01 tag is what keeps an internal node from
/// ever colliding with a leaf, which is hashed under 0x00.
/// @param a One child.
/// @param b The other child.
/// @return The parent node.
function _pair(bytes32 a, bytes32 b) private pure returns (bytes32) {
(bytes32 lo, bytes32 hi) = a < b ? (a, b) : (b, a);
return keccak256(abi.encodePacked(bytes1(0x01), lo, hi));
}
/// @notice Collect the siblings from a slot up a given number of levels.
/// @dev The sibling path from a slot up `height` levels. One routine serves
/// the branch proof and the tree proof; only the height differs, which
/// is why the two can never disagree about a shared prefix.
/// @param treeId The tree to read.
/// @param idx The starting slot. Consumed as the walk climbs.
/// @param height How many levels to climb.
/// @return path The siblings, lowest level first.
function _path(uint8 treeId, uint256 idx, uint256 height) private view returns (bytes32[] memory path) {
path = new bytes32[](height);
for (uint256 l = 0; l < height; l++) {
path[l] = _nodeAt(treeId, l, idx ^ 1);
idx >>= 1;
}
}
/// @notice Lay the tree roots out as the leaves of the round tree.
/// @dev The forest's leaves: the tree roots at their positions, the
/// empty tree at the rest. Tree `t` sits at position `t`, so the
/// round proof's index is the tree id with no translation, and the
/// unused positions hold the empty TREE root rather than zero — they
/// are genuinely empty trees, and hashing them as zero would make the
/// round root unreproducible off chain.
/// @param roots The round's tree roots, indexed by tree id.
/// @return level The `1 << FOREST_BITS` leaves of the round tree.
function _forestLeaves(bytes32[TREE_COUNT + 1] memory roots) private view returns (bytes32[] memory level) {
level = new bytes32[](1 << FOREST_BITS);
for (uint256 p = 0; p < level.length; p++) {
level[p] = (p >= 1 && p <= TREE_COUNT) ? roots[p] : _zero[DEPTH];
}
}
/// @notice Fold the round tree's leaves down to the round root.
/// @dev Fold a power-of-two level to its root, in place. The input array is
/// overwritten, so the caller must not reuse it afterwards.
/// @param level The level to fold. Length must be a power of two.
/// @return The root of that level.
function _foldForest(bytes32[] memory level) private pure returns (bytes32) {
for (uint256 n = level.length; n > 1; n >>= 1) {
for (uint256 i = 0; i < n / 2; i++) {
level[i] = _pair(level[2 * i], level[2 * i + 1]);
}
}
return level[0];
}
/// @notice Place one leaf, assigning the key a permanent slot on first sight.
/// @dev The single point every write door funnels through, which is what
/// makes the slot discipline unconditional: a key is handed the next
/// free position in its branch, remembered in both directions, and
/// keeps it for the life of the contract. A key that already holds a
/// slot in a DIFFERENT branch is refused rather than moved — moving it
/// would silently invalidate every proof anyone holds for it.
///
/// The update then rehashes exactly `DEPTH` nodes up the leaf's own
/// path, so the cost of a write is the height of the tree and not the
/// number of leaves in it. This is also where the tree's shape comes
/// from: fixed height, zero-padded siblings, insertion-ordered slots.
/// @param treeId The tree to write.
/// @param branch The branch the key belongs to.
/// @param key The domain key.
/// @param leaf The raw (untagged) value to store.
function _set(uint8 treeId, uint8 branch, bytes32 key, bytes32 leaf) private {
uint256 s = _slotPlusOne[treeId][key];
uint256 idx;
if (s == 0) {
uint256 used = _branchSlotsUsed[treeId][branch];
if (used >= BRANCH_CAPACITY) revert BranchFull(treeId, branch);
idx = (uint256(branch) << BRANCH_DEPTH) | used;
_branchSlotsUsed[treeId][branch] = used + 1;
slotsUsed[treeId] += 1;
_slotPlusOne[treeId][key] = idx + 1;
_keyAt[treeId][idx] = key;
} else {
idx = s - 1;
uint8 have = uint8(idx >> BRANCH_DEPTH);
if (have != branch) revert BranchMismatch(treeId, key, have, branch);
}
_leaf[treeId][idx] = leaf;
bytes32 cursor = keccak256(abi.encodePacked(bytes1(0x00), leaf));
for (uint256 l = 0; l < DEPTH; l++) {
cursor = _pair(cursor, _nodeAt(treeId, l, idx ^ 1));
idx >>= 1;
_node[treeId][l + 1][idx] = cursor;
}
liveRoot[treeId] = cursor;
}
/// @notice One node of a tree, at any level, with empty positions filled in.
/// @dev Level 0 is derived from the leaf store rather than duplicated into
/// `_node`, so there is one place a leaf lives and no way for the two to
/// disagree. Unset positions fall through to the empty-subtree hash — the
/// zero padding that gives the tree its fixed height, and the reason an
/// off-chain rebuild must pad to the same height to reach the same root.
/// @param treeId The tree to read.
/// @param level The level, 0 being the leaves.
/// @param index The position at that level.
/// @return The node, or the empty-subtree hash when nothing was written there.
function _nodeAt(uint8 treeId, uint256 level, uint256 index) private view returns (bytes32) {
if (level == 0) {
return keccak256(abi.encodePacked(bytes1(0x00), _leaf[treeId][index]));
}
bytes32 v = _node[treeId][level][index];
return v == bytes32(0) ? _zero[level] : v;
}
// ------------------------------------------------------------------ sweep
/// @notice The registry the inherited sweep authority resolves members through.
/// @dev This contract's configuration gate reads the membership registry it
/// was constructed against, so the sweep authority reads the same one. One
/// registry for both means a member removed from the roster loses the sweep
/// at the same instant it loses everything else.
/// @return The immutable identity registry pinned at construction.
function _sweepRegistry() internal view override returns (FinalIdentityRegistry) {
return registry;
}
/// @dev Nothing is reserved because nothing is owed: this contract has no
/// payable entrypoint and no custody line — it records, it does not hold.
/// Anything it carries arrived by accident and is sweepable in full.
}
contracts/utils/FinalBundleTree.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may link against and call this bundle-root fold, and
// may build an off-chain bundle assembler that reproduces it, as part of the
// Final DeFi Protocol.
// 2. Protocol operators, integrators, and end users may have bundles rooted and
// anchored through any Final DeFi surface that embeds it.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this bundle-root fold or a competing bundle
// anchoring scheme without permission prior to the Change Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
/// @notice Thrown when a fold is attempted over an empty leaf layer, which commits to nothing.
/// @dev Declared at file level rather than inside the library so that every surface refusing an empty bundle
/// reverts with the SAME selector: `PqAnchorModule` and `PaymasterModule` on an execution chain, and the
/// bundle log on Final Chain. An off-chain caller decoding the failure therefore gets one answer no
/// matter which side refused, and cannot mistake an empty bundle for an unrelated fault.
error EmptyBundleTree();
/**
* @title Final Bundle Tree
* @notice The single definition of the fold from a bundle's intent leaves to its bundle root.
* @dev Two chains compute this root independently and must agree exactly. An execution chain's gateway folds
* it from the intents it is about to dispatch; the bundle log on Final Chain folds it from the leaves
* being anchored, so that the payload it stores is RECOMPUTED rather than asserted by whoever assembled
* the transaction. A divergence between the two would not surface as a failed verification — it would be
* a bundle that anchors on Final Chain and can never execute anywhere, with nothing naming the cause.
* That is why the fold lives here once instead of being written twice. Any off-chain assembler that
* predicts a bundle root must reproduce it identically, down to the tag bytes.
*
* ## Preimage layouts
*
* - interior pair: `keccak256(POS_NODE(1) || DOMAIN_PQ_NODE(32) || left(32) || right(32))` — 97 bytes
* - odd-tail lift: `keccak256(POS_LIFT(1) || DOMAIN_PQ_NODE(32) || value(32))` — 65 bytes
*
* `DOMAIN_PQ_NODE` is `keccak256("FINAL_PQ_BUNDLE_NODE_v01")`. It separates this commitment space from
* every other Merkle surface in the system, so a node from another tree cannot be replayed as a node here
* even when the raw hashes line up.
*
* ## Tree shape
*
* Insertion-ordered and POSITIONAL: leaves are folded left to right in the order given, pairs are never
* sorted, and the tree is neither fixed-depth nor zero-padded. Each layer takes elements two at a time;
* an element left over at the end of a layer is LIFTED to the next layer under its own tag rather than
* paired with itself or carried through untouched. Folding continues until one element remains, which is
* the root; a single-leaf layer roots to that leaf's own hash unchanged.
*
* The lift tag is the whole point of the odd-tail branch. `POS_LIFT` differs from `POS_NODE`, and lifting
* changes the value, so `Root([a, b, c]) != Root([a, b, c, c])`. Under a self-pairing convention those
* two layers collapse to the same root and a bundle could be re-presented with its last intent silently
* duplicated. Carrying the odd element through unchanged would be worse still, letting a leaf value and
* an interior value occupy the same position.
*
* This library folds a layer and nothing else. It does not build leaves, does not know what a leaf
* commits to, and takes no view on whether the layer it was handed is the right one — those belong to the
* surface that owns the intent leaf preimage.
*/
library FinalBundleTree {
/// @notice One-byte position tag opening the preimage of an interior node built from two children.
/// @dev Nonzero, and distinct from {POS_LIFT}, so that neither an intent leaf nor a lifted element can be
/// reinterpreted as a paired node.
uint8 internal constant POS_NODE = 0x01;
/// @notice One-byte position tag opening the preimage of a lifted odd trailing element.
/// @dev Distinct from {POS_NODE} so a lift and a pair are different commitments even over the same bytes.
/// This is what makes an odd layer and the same layer with its tail duplicated root differently.
uint8 internal constant POS_LIFT = 0x02;
/// @notice Domain separator carried in every interior preimage of a bundle tree, paired and lifted alike.
/// @dev `keccak256("FINAL_PQ_BUNDLE_NODE_v01")`. Every producer of a bundle root — this gateway, the
/// Final Chain bundle log, and any off-chain assembler — must hash this exact value in this exact
/// position, or the roots diverge and the bundle anchors to something that can never execute.
bytes32 internal constant DOMAIN_PQ_NODE = keccak256("FINAL_PQ_BUNDLE_NODE_v01");
/**
* @notice Fold a layer of leaves into the single root that commits to all of them, in order.
* @dev Takes a LAYER rather than a bundle, deliberately. A bundle may carry both post-quantum and
* pre-quantum rows, and only the post-quantum subset is anchored: Final Chain never saw the other
* rows and cannot commit to leaves it did not build. Passing the subset lets both sides fold exactly
* the same list.
*
* Order is significant and is never normalised. The caller is responsible for presenting leaves in
* the same order the anchoring side used; a permuted layer folds to a different root and fails
* closed rather than verifying against some other arrangement.
*
* Mutates nothing the caller can observe. `leaves` is read on the first pass and never written, and
* every subsequent layer is a freshly allocated array, so the caller's array survives the call intact
* and may be reused.
* @param leaves The ordered layer to fold; must be non-empty.
* @return root The bundle root committing to exactly these leaves in exactly this order.
*/
function foldLeaves(bytes32[] memory leaves) internal pure returns (bytes32 root) {
if (leaves.length == 0) revert EmptyBundleTree();
bytes32[] memory layer = leaves;
while (layer.length > 1) {
uint256 srcLen = layer.length;
uint256 pairCount = srcLen >> 1;
uint256 oddTail = srcLen & 1;
bytes32[] memory next = new bytes32[](pairCount + oddTail);
for (uint256 i = 0; i < pairCount; i++) {
next[i] = keccak256(
abi.encodePacked(POS_NODE, DOMAIN_PQ_NODE, layer[i << 1], layer[(i << 1) | 1])
);
}
if (oddTail == 1) {
next[pairCount] = keccak256(
abi.encodePacked(POS_LIFT, DOMAIN_PQ_NODE, layer[srcLen - 1])
);
}
layer = next;
}
return layer[0];
}
}
contracts/utils/FinalMmr.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may link against and call this inclusion-proof
// library, and may build an off-chain log that produces proofs it accepts,
// as part of the Final DeFi Protocol.
// 2. Protocol operators, integrators, and end users may have their inclusion
// proofs verified through any Final DeFi surface that embeds it.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this inclusion-proof library or a competing
// append-only-log anchor without permission prior to the Change Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
/**
* @title Final MMR
* @notice Inclusion and consistency verification against an append-only log — a Merkle mountain range over the
* log's perfect subtrees, positional and domain-separated.
* @dev The algorithm is the RFC 6962 inclusion decomposition, which verifies a leaf against the Merkle tree
* hash of a log of ARBITRARY size rather than only a power-of-two one. A log of `size` leaves decomposes
* into perfect subtrees whose roots are its peaks; a proof walks the leaf up through its own subtree and
* then bags the peaks to its left.
*
* ## Canonical layout — an off-chain log MUST match this byte for byte
*
* - leaf: `keccak256(0x00 || domain || payload)` — 65 bytes
* - node: `keccak256(0x01 || domain || left || right)` — 97 bytes
*
* `left` is ALWAYS the lower-index child. This construction is positional and is never sorted: position
* is exactly what an inclusion proof claims, so sorting the pair would discard the claim.
*
* The one-byte `0x00` / `0x01` tags are the load-bearing safety property. Without them a 64-byte interior
* preimage could be re-presented as a leaf preimage and vice versa, which is the second-preimage class
* that untagged and sorted constructions leave open. `domain` is the caller's commitment-space separator,
* so two logs that share this library cannot have a proof from one accepted by the other even when both
* commit to the same payload bytes.
*
* ## Proof shape is derived, never supplied
*
* A proof is `(index, size, proof[])`, where `index` is the 0-based leaf position and `size` is the total
* leaf count the root commits to. The path's length AND its left/right schedule are fully determined by
* `(index, size)`:
*
* - `inner = bitLength(index ^ (size - 1))` positional siblings, each combined on the side that bit `i`
* of `index` dictates, followed by
* - `border = popcount(index >> inner)` perfect-subtree peaks, each folded in as a LEFT sibling, which is
* the right-to-left peak bag.
*
* Because both numbers come from `(index, size)` and never from the prover, a padded, truncated or
* reshaped proof cannot silently validate: `computeRoot` reverts on a length mismatch and on an
* out-of-range index rather than returning some other root.
*
* ## A proof is specific to the SIZE it was produced against
*
* This is the property that most often surprises an integrator. An append-only log has a different root
* at every size, and the decomposition above changes shape as `size` grows: appending leaves can change
* how many peaks sit to the left of a given index, and therefore both `inner` and `border`. A proof
* generated against size `n` is a proof about the root at size `n` and nothing else. Presented against
* the root at a later size it does not verify — usually by reverting with a length mismatch, and where
* the two shapes happen to coincide by recomputing a root that simply is not equal to the anchor. It is
* never accepted, but it is also never repairable by retrying, so an off-chain producer must generate the
* proof against the exact size the consuming contract has anchored, not against the head of the log.
* That is why every entrypoint here takes `size` as an explicit argument: the verifier has no way to
* discover it and must be told which historical root the proof is about.
*
* ## A head must extend the head before it
*
* Monotonicity of `size` says nothing about the leaves: a root at `size + 1` can commit to any history at
* all. {verifyConsistency} closes that with the RFC 6962 consistency proof — the `~log2(size)` subtree
* roots that bridge two heads — so a contract holding `(root, size)` can require that the head it is
* handed next commits to every leaf the current one does, in the same positions, plus appended ones.
* Whoever advances the head can then append and can never rewrite.
*
* Pure library: no storage, no external calls, no upgrade surface. Hashing goes through `abi.encodePacked`
* rather than hand-written assembly, because the cost is one inclusion proof per bundle — roughly log2 of
* the log size in hashes — and legibility of the exact preimage is worth more here than the saved gas.
*/
library FinalMmr {
/// @notice One-byte tag that opens every leaf preimage, ahead of `domain` and the payload.
/// @dev Distinct from {NODE_TAG} so a 64-byte interior preimage can never be reinterpreted as a leaf.
uint8 internal constant LEAF_TAG = 0x00;
/// @notice One-byte tag that opens every interior-node preimage, ahead of `domain` and the two children.
/// @dev Distinct from {LEAF_TAG} for the same reason, in the other direction.
uint8 internal constant NODE_TAG = 0x01;
/// @notice Thrown when the leaf index is not strictly less than the `size` the root commits to.
/// @param index The 0-based leaf position that was supplied.
/// @param size The committed leaf count the proof was checked against.
error MmrIndexOutOfRange(uint256 index, uint256 size);
/// @notice Thrown when the supplied path length does not equal the one `(index, size)` implies.
/// @dev The overwhelmingly common cause is a proof produced against a different log size than the one the
/// verifying contract has anchored.
/// @param expected Path length derived from `(index, size)`.
/// @param actual Path length that was supplied.
error MmrProofLengthMismatch(uint256 expected, uint256 actual);
/// @notice Thrown when `size` is zero: an empty log commits to no leaves, so nothing can be included in it.
error MmrEmptyLog();
/// @notice Thrown when a consistency proof cannot bridge the `(oldSize, newSize)` pair it was supplied for —
/// too few or too many elements for those two shapes.
/// @param oldSize Leaf count of the anchored head.
/// @param newSize Leaf count of the proposed head.
/// @param supplied Elements in the supplied path.
error MmrConsistencyProofMalformed(uint256 oldSize, uint256 newSize, uint256 supplied);
/// @notice Thrown when the proposed head does not hold more leaves than the anchored one: there is no growth
/// for a consistency proof to speak about.
/// @param oldSize Leaf count of the anchored head.
/// @param newSize Leaf count of the proposed head.
error MmrSizeNotGrowing(uint256 oldSize, uint256 newSize);
/// @notice Tag and hash a payload into an MMR leaf: `keccak256(0x00 || domain || payload)`, 65 bytes.
/// @dev The single place a leaf preimage is built, so the producer of a log and the verifier of a proof
/// cannot drift. An off-chain log that builds leaves any other way produces proofs nothing accepts.
/// @param domain Commitment-space separator; must be the same value the proof will later be checked under.
/// @param payload The value being committed as a leaf, such as a bundle root.
/// @return leaf The tagged, domain-separated leaf hash.
function hashLeaf(bytes32 domain, bytes32 payload) internal pure returns (bytes32 leaf) {
return keccak256(abi.encodePacked(LEAF_TAG, domain, payload));
}
/// @notice Hash one interior node: `keccak256(0x01 || domain || left || right)`, 97 bytes.
/// @dev Positional, never sorted — `left` is the lower-index child and the caller is responsible for
/// putting it there. Private because the ordering decision belongs to {computeRoot}, which derives it
/// from `index`; exposing it would let a caller choose an order the proof shape does not imply.
/// @param domain Commitment-space separator, identical to the one used for the leaves below this node.
/// @param left The lower-index child.
/// @param right The higher-index child.
/// @return node The tagged, domain-separated interior-node hash.
function _hashNode(bytes32 domain, bytes32 left, bytes32 right) private pure returns (bytes32 node) {
return keccak256(abi.encodePacked(NODE_TAG, domain, left, right));
}
/// @notice Recompute the append-only-log root that a leaf's inclusion proof implies.
/// @dev Fails closed. An out-of-range index, an empty log, or a path whose length does not match the
/// `(index, size)` decomposition all revert rather than returning some other root, so a caller can
/// never mistake a structurally invalid proof for a proof of a different leaf. What this function does
/// NOT do is decide trust: it returns a root, and the caller compares it against the anchor it holds.
///
/// The result is only meaningful for the `size` supplied. See the size-specificity note on this
/// library: a path built against a different log size is rejected here, not silently reinterpreted.
/// @param leaf The leaf hash, already tagged by {hashLeaf}; passing an untagged payload verifies nothing.
/// @param index 0-based position of the leaf in the log.
/// @param size Total leaf count the target root commits to.
/// @param domain Commitment-space separator; must equal the one the leaf was tagged with.
/// @param proof Audit path: `inner` positional siblings, then `border` peak hashes.
/// @return root The recomputed log root, for the caller to compare against its anchor.
function computeRoot(
bytes32 leaf,
uint256 index,
uint256 size,
bytes32 domain,
bytes32[] memory proof
) internal pure returns (bytes32 root) {
if (size == 0) revert MmrEmptyLog();
if (index >= size) revert MmrIndexOutOfRange(index, size);
// The RFC 6962 decomposition. `inner` counts the levels at which this leaf still has a sibling inside
// its own (possibly imperfect) subtree; `border` counts the completed peaks to its left that must be
// bagged in afterwards. Both come from `(index, size)`, so the prover has no say in the path's shape.
uint256 inner = bitLength(index ^ (size - 1));
uint256 border = popcount(index >> inner);
uint256 expectedLen = inner + border;
if (proof.length != expectedLen) revert MmrProofLengthMismatch(expectedLen, proof.length);
bytes32 res = leaf;
// Phase 1: `inner` positional combines. Bit `i` of `index` decides the side — 0 puts the running hash
// on the left, 1 on the right — so the path carries no direction bits a prover could flip.
for (uint256 i = 0; i < inner; ) {
bytes32 sibling = proof[i];
if ((index >> i) & 1 == 0) {
res = _hashNode(domain, res, sibling); // running hash is the left child
} else {
res = _hashNode(domain, sibling, res); // running hash is the right child
}
unchecked { ++i; }
}
// Phase 2: the peak bag. Every remaining element is a completed perfect-subtree peak to the LEFT of
// this leaf's subtree, so each is folded in as the left operand, right to left.
for (uint256 i = inner; i < expectedLen; ) {
res = _hashNode(domain, proof[i], res);
unchecked { ++i; }
}
return res;
}
/// @notice Verify that `leaf` is the `index`-th of `size` leaves committed to by `root`.
/// @dev A thin wrapper over {computeRoot}; the leaf must already be tagged by {hashLeaf}. `false` means one
/// thing only — the recomputed root differs from `root`. A structurally invalid proof does not reach
/// that comparison: it reverts inside {computeRoot}, so a caller cannot conflate "not included" with
/// "malformed" and must not treat `false` as evidence that the proof was well formed.
/// @param leaf The leaf hash, already tagged by {hashLeaf}.
/// @param index 0-based position of the leaf in the log.
/// @param size Total leaf count `root` commits to; the proof is specific to this value.
/// @param domain Commitment-space separator; must equal the one the leaf was tagged with.
/// @param proof Audit path: `inner` positional siblings, then `border` peak hashes.
/// @param root The trusted anchor to compare against.
/// @return Whether the proof places `leaf` at `index` in the log `root` commits to.
function verifyInclusion(
bytes32 leaf,
uint256 index,
uint256 size,
bytes32 domain,
bytes32[] memory proof,
bytes32 root
) internal pure returns (bool) {
return computeRoot(leaf, index, size, domain, proof) == root;
}
/// @notice Verify inclusion of a raw, untagged `payload`, tagging it into a leaf internally.
/// @dev The entrypoint to prefer when the caller holds the committed value rather than a leaf hash: it
/// makes it impossible to present an interior node hash as a leaf, because the `0x00` tag is applied
/// here and cannot be supplied by the caller.
/// @param payload The raw value committed as a leaf, such as a bundle root.
/// @param index 0-based position of the leaf in the log.
/// @param size Total leaf count `root` commits to; the proof is specific to this value.
/// @param domain Commitment-space separator, applied to both the leaf and every node.
/// @param proof Audit path: `inner` positional siblings, then `border` peak hashes.
/// @param root The trusted anchor to compare against.
/// @return Whether the proof places `payload` at `index` in the log `root` commits to.
function verifyInclusionOfPayload(
bytes32 payload,
uint256 index,
uint256 size,
bytes32 domain,
bytes32[] memory proof,
bytes32 root
) internal pure returns (bool) {
return computeRoot(hashLeaf(domain, payload), index, size, domain, proof) == root;
}
/// @notice Verify that the log `newRoot` commits to at `newSize` leaves EXTENDS the log `oldRoot` commits to
/// at `oldSize`: the first `oldSize` leaves are the same, in the same positions, and nothing the old
/// head held has been rewritten.
/// @dev The RFC 6962 consistency proof, checked with the RFC 9162 §2.1.4.2 procedure over this library's
/// tagged, domain-separated, positional nodes. The path is the set of subtree roots that bridge the two
/// heads — about `log2(newSize)` hashes — and both roots are recomputed from it: `oldRoot` from the old
/// tree's right spine, `newRoot` from that spine plus the appended subtrees. A path that reconstructs
/// both is a proof that the new head is the old head with leaves appended and nothing else.
///
/// Fails closed like {computeRoot}: a path whose length does not fit the `(oldSize, newSize)` pair
/// reverts rather than returning `false`, so a caller can never mistake a malformed path for a rewritten
/// history or the other way round. `false` means exactly one thing — the reconstructed roots do not meet
/// the anchors.
///
/// Two sizes are refused rather than proven. An empty old head (`oldSize == 0`) has no history to be
/// consistent with; what the first head may be is the caller's decision. A non-growing size is refused
/// because the procedure is undefined for it, and the caller's own monotonicity check names that failure.
///
/// The producer is the RFC 6962 §2.1.2 recursion (`SUBPROOF`), and it is also derivable from ONE
/// inclusion proof: the path for leaf `oldSize - 1` at `newSize`, with its lowest `t` siblings (`t` the
/// trailing zero bits of `oldSize`) folded into the old tree's right-spine node and that node prepended
/// unless `oldSize` is a power of two. A log that serves inclusion proofs therefore serves this one too.
/// @param oldRoot The anchored head's root.
/// @param oldSize Leaf count `oldRoot` commits to; must be non-zero.
/// @param newRoot The proposed head's root.
/// @param newSize Leaf count `newRoot` commits to; must exceed `oldSize`.
/// @param domain Commitment-space separator both heads were built under.
/// @param proof The consistency path in RFC 6962 order: the old tree's right-spine node first, when the old
/// tree is not perfect, then one sibling per level upward.
/// @return Whether `newRoot` at `newSize` extends `oldRoot` at `oldSize`.
function verifyConsistency(
bytes32 oldRoot,
uint256 oldSize,
bytes32 newRoot,
uint256 newSize,
bytes32 domain,
bytes32[] memory proof
) internal pure returns (bool) {
if (oldSize == 0) revert MmrEmptyLog();
if (newSize <= oldSize) revert MmrSizeNotGrowing(oldSize, newSize);
// RFC 9162 §2.1.4.2. `fn` and `sn` walk the two trees' node indices upward from the leaf level; the
// path is consumed in the order the RFC prover emits it.
uint256 fn = oldSize - 1;
uint256 sn = newSize - 1;
// The old tree's complete right spine says nothing its root does not already say: skip those levels.
while (fn & 1 == 1) {
fn >>= 1;
sn >>= 1;
}
uint256 i;
bytes32 fr;
bytes32 sr;
if (oldSize & (oldSize - 1) == 0) {
// A perfect old tree IS its root, so the prover omits it and the verifier supplies it.
fr = oldRoot;
sr = oldRoot;
} else {
if (proof.length == 0) revert MmrConsistencyProofMalformed(oldSize, newSize, 0);
fr = proof[0];
sr = proof[0];
i = 1;
}
for (; i < proof.length; ) {
// A path that keeps going after the new root has been reached is not a path in this tree.
if (sn == 0) revert MmrConsistencyProofMalformed(oldSize, newSize, proof.length);
bytes32 c = proof[i];
if (fn & 1 == 1 || fn == sn) {
// A LEFT sibling of both walks — a subtree the old head already held, folded into both roots.
fr = _hashNode(domain, c, fr);
sr = _hashNode(domain, c, sr);
if (fn & 1 == 0) {
while (fn != 0 && fn & 1 == 0) {
fn >>= 1;
sn >>= 1;
}
}
} else {
// A RIGHT sibling of the new walk only — an appended subtree the old head never saw.
sr = _hashNode(domain, sr, c);
}
fn >>= 1;
sn >>= 1;
unchecked { ++i; }
}
// The walk must end exactly at the new root, and both reconstructions must meet their anchors.
if (sn != 0) revert MmrConsistencyProofMalformed(oldSize, newSize, proof.length);
return fr == oldRoot && sr == newRoot;
}
/// @notice Bit length of `x`: the position of its highest set bit plus one, and `0` when `x` is zero.
/// @dev `internal` rather than `private` on purpose, so that a contract producing proofs derives their
/// shape with the SAME arithmetic the verifier uses to check it. Two independent copies of this
/// decomposition means proofs built to one shape and checked against another, and the resulting
/// failure names neither side.
/// @param x Value to measure.
/// @return n Number of significant bits in `x`.
function bitLength(uint256 x) internal pure returns (uint256 n) {
while (x != 0) {
x >>= 1;
unchecked { ++n; }
}
}
/// @notice Population count of `x`: how many of its bits are set.
/// @dev `internal` for the same reason as {bitLength} — the producer of a proof and its verifier must count
/// peaks with one implementation, not two.
/// @param x Value to measure.
/// @return c Number of set bits in `x`.
function popcount(uint256 x) internal pure returns (uint256 c) {
while (x != 0) {
unchecked {
c += x & 1;
x >>= 1;
}
}
}
}
contracts/utils/FinalSweep.sol
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2024-2026 Final DeFi
// Licensed under the Business Source License 1.1 (the "License")
//
// Change Date: 2029-01-01
// Change License: GPL-2.0-or-later
//
// Additional Use Grant:
// 1. Any person or entity may inherit this sweep surface into contracts that
// integrate with the Final DeFi Protocol, in order to recover assets sent to
// them by mistake.
// 2. Protocol operators and integrators may call the sweep entrypoints it
// declares, subject to each inheriting contract's own authority and reserved
// balance rules, as part of their integration with the Final DeFi Protocol.
// 3. For the avoidance of doubt, this Grant does NOT permit the commercial
// deployment of a Fork of this sweep surface or a competing asset-recovery
// plane derived from it without permission prior to the Change Date.
//
// @author Final DeFi
// @version 1.0.0
pragma solidity ^0.8.20;
/// @notice The asset kinds a sweep can move. `Native` ignores `asset` and
/// `id`; `Erc20` ignores `id`; `Erc721` reads `id` as the token id and moves
/// exactly one; `Erc1155` reads both.
enum SweepKind { Native, Erc20, Erc721, Erc1155 }
/**
* @title Final Sweep
* @notice One sweep surface, on every contract of ours that can end up holding
* an asset it does not owe to anybody.
*
* @dev Assets arrive at protocol contracts that were never meant to hold them:
* a bridge delivers to the wrong leg, a user sends an ERC-20 to a registry, an
* airdrop lands on the gateway, an NFT is safe-transferred into the vault. Left
* alone that value is destroyed. The sweep is how it comes back — and the
* single rule it must never break is that a sweep moves SURPLUS and nothing
* else.
*
* Three seams make that rule per-contract:
*
* - `_requireSweepAuthority()` — the treasury role, expressed in whatever
* access plane the host contract already has (`FinalAccessController` roles,
* a cross-chain authority, a quorum). No new authority is introduced.
* - `_sweepDestinations()` — where a sweep may pay. Ours is a two-address
* answer because a contract normally has exactly two legitimate ones (the
* gateway and the treasury); a contract with one returns it twice.
* `FinalGateway` overrides `_requireSweepDestination` outright: the gateway
* is the drain of the whole system and sweeps ONWARD to anywhere.
* - `_sweepReserved(kind, asset, id)` — the part of the raw balance that is
* NOT surplus: fee deposits, the pending-settlement bucket, searcher
* collateral, settlement custody, vaulted entries, locked PHI. The default
* is zero, which is correct for a contract that custodies nothing; every
* contract that custodies something overrides it and is the one place the
* liability is stated.
*
* The surplus is measured LIVE against the raw balance at call time, so a
* re-entrant destination re-measures against a balance that already fell —
* there is no cached figure to double-spend. Nothing here writes storage, so
* there is no state for a callback to observe half-updated either.
*
* The three ERC-721/ERC-1155 receiver hooks are part of the same surface and
* for the same reason: `safeTransferFrom` reverts into a contract that does not
* answer them, so without these an NFT sent to one of ours does not land at
* all — which is not safety, it is a different way to lose it.
*/
abstract contract FinalSweep {
/// @notice `msg.sender` does not hold this contract's sweep authority.
error SweepUnauthorized(address caller);
/// @notice `to` is neither of this contract's sweep destinations.
error SweepDestinationNotAllowed(address to);
/// @notice The requested amount is above the surplus: the difference is
/// owed to somebody (a deposit, a custody total, a vaulted entry).
error SweepAboveSurplus(address asset, uint256 requested, uint256 surplus);
/// @notice A sweep of nothing.
error SweepZeroAmount();
/// @notice The transfer leg failed, or the token returned `false`.
error SweepTransferFailed(address asset);
/// @notice `amount` of `asset` (`id` for the non-fungible kinds) left this
/// contract for `to` under the sweep authority.
event AssetSwept(SweepKind indexed kind, address indexed asset, address indexed to, uint256 id, uint256 amount);
// ─────────────────────────────── seams ───────────────────────────────
/// @dev Reverts unless `msg.sender` may sweep. The host contract's own
/// treasury role — never a new one.
function _requireSweepAuthority() internal view virtual;
/// @dev The (at most two) addresses a sweep may pay. A contract with one
/// legitimate destination returns it twice.
function _sweepDestinations() internal view virtual returns (address a, address b);
/// @dev The part of the raw balance that is owed and therefore never
/// sweepable. Zero for a contract that custodies nothing.
function _sweepReserved(SweepKind, address, uint256) internal view virtual returns (uint256) {
return 0;
}
/// @dev Destination policy. Overridden by `FinalGateway`, which may sweep
/// onward to anywhere.
function _requireSweepDestination(address to) internal view virtual {
(address a, address b) = _sweepDestinations();
if (to == address(0) || (to != a && to != b)) revert SweepDestinationNotAllowed(to);
}
// ────────────────────────────── surface ──────────────────────────────
/// @notice The surplus of `asset` (`id` for the non-fungible kinds) — the
/// raw balance above everything this contract owes. What a sweep may move,
/// readable before calling one.
function sweepableSurplus(SweepKind kind, address asset, uint256 id) public view returns (uint256 surplus) {
uint256 raw = _rawBalance(kind, asset, id);
uint256 reserved = _sweepReserved(kind, asset, id);
return raw > reserved ? raw - reserved : 0;
}
/// @notice Move `amount` of an asset this contract does not owe to `to`.
/// @dev Role-gated, destination-gated and bounded by the live surplus. The
/// three gates are independent: a treasury key cannot pay a destination
/// the contract does not recognize, and neither key nor destination can
/// reach a wei that backs a liability.
/// @param kind Which asset kind is being moved.
/// @param asset Token contract; ignored for `Native`.
/// @param id Token id for `Erc721` / `Erc1155`; ignored otherwise.
/// @param amount Amount to move. `type(uint256).max` means the whole
/// surplus, which is what an operator draining a stray balance wants and
/// what avoids a race with an inflow landing between the read and the call.
/// @param to Destination.
/// @return moved Amount actually moved.
function sweepAsset(SweepKind kind, address asset, uint256 id, uint256 amount, address to)
external
returns (uint256 moved)
{
_requireSweepAuthority();
_requireSweepDestination(to);
uint256 surplus = sweepableSurplus(kind, asset, id);
moved = amount == type(uint256).max ? surplus : amount;
if (moved == 0) revert SweepZeroAmount();
if (moved > surplus) revert SweepAboveSurplus(asset, moved, surplus);
if (kind == SweepKind.Native) {
(bool ok,) = payable(to).call{value: moved}("");
if (!ok) revert SweepTransferFailed(address(0));
} else if (kind == SweepKind.Erc20) {
_callToken(asset, abi.encodeWithSelector(0xa9059cbb, to, moved)); // transfer(address,uint256)
} else if (kind == SweepKind.Erc721) {
// `transferFrom`, not `safeTransferFrom`: a rescue must not fail
// because the treasury destination declines a hook. Which
// destination is legitimate is already decided above.
moved = 1;
_callToken(asset, abi.encodeWithSelector(0x23b872dd, address(this), to, id)); // transferFrom
} else {
_callToken(
asset,
abi.encodeWithSelector(0xf242432a, address(this), to, id, moved, "") // safeTransferFrom(...)
);
}
emit AssetSwept(kind, asset, to, id, moved);
}
// ───────────────────────────── receivers ─────────────────────────────
/// @notice Accept safe ERC-721 transfers, so one sent here is recoverable
/// rather than rejected at the door.
function onERC721Received(address, address, uint256, bytes calldata) external pure virtual returns (bytes4) {
return 0x150b7a02;
}
/// @notice Accept safe ERC-1155 single transfers.
function onERC1155Received(address, address, uint256, uint256, bytes calldata)
external
pure
virtual
returns (bytes4)
{
return 0xf23a6e61;
}
/// @notice Accept safe ERC-1155 batch transfers.
function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata)
external
pure
virtual
returns (bytes4)
{
return 0xbc197c81;
}
// ───────────────────────────── internals ─────────────────────────────
/// @dev The raw held amount, before anything owed is subtracted.
function _rawBalance(SweepKind kind, address asset, uint256 id) internal view returns (uint256) {
if (kind == SweepKind.Native) return address(this).balance;
if (kind == SweepKind.Erc20) {
(bool ok, bytes memory ret) = asset.staticcall(abi.encodeWithSelector(0x70a08231, address(this)));
return (ok && ret.length >= 32) ? abi.decode(ret, (uint256)) : 0;
}
if (kind == SweepKind.Erc721) {
(bool ok, bytes memory ret) = asset.staticcall(abi.encodeWithSelector(0x6352211e, id)); // ownerOf
return (ok && ret.length >= 32 && abi.decode(ret, (address)) == address(this)) ? 1 : 0;
}
(bool ok1155, bytes memory ret1155) =
asset.staticcall(abi.encodeWithSelector(0x00fdd58e, address(this), id)); // balanceOf(address,uint256)
return (ok1155 && ret1155.length >= 32) ? abi.decode(ret1155, (uint256)) : 0;
}
/// @dev One transfer leg, tolerant of the legacy no-return ERC-20 shape the
/// way `FinalDeployer`'s rescue helpers are: success is "the call did not
/// revert AND it did not return `false`".
function _callToken(address token, bytes memory data) private {
if (token.code.length == 0) revert SweepTransferFailed(token);
(bool ok, bytes memory ret) = token.call(data);
if (!ok || (ret.length != 0 && !abi.decode(ret, (bool)))) revert SweepTransferFailed(token);
}
}
abi
[
{
"type": "constructor",
"inputs": [
{
"name": "registry_",
"type": "address",
"internalType": "contract FinalIdentityRegistry"
},
{
"name": "intentLog_",
"type": "address",
"internalType": "contract FinalIntentLog"
}
],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "ACTION_CONFIGURE",
"inputs": [],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "ACTION_SEED",
"inputs": [],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "ACTION_SEED_PAYLOADS",
"inputs": [],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "DOMAIN",
"inputs": [],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "append",
"inputs": [
{
"name": "termsLeaves",
"type": "bytes32[]",
"internalType": "bytes32[]"
},
{
"name": "bundles",
"type": "bytes32[][]",
"internalType": "bytes32[][]"
},
{
"name": "anchorBlock",
"type": "uint64",
"internalType": "uint64"
},
{
"name": "approvals",
"type": "tuple[]",
"internalType": "struct FinalPqQuorum.Approval[]",
"components": [
{
"name": "signer",
"type": "address",
"internalType": "address"
},
{
"name": "algorithm",
"type": "uint8",
"internalType": "uint8"
},
{
"name": "signature",
"type": "bytes",
"internalType": "bytes"
},
{
"name": "seal",
"type": "bytes",
"internalType": "bytes"
}
]
}
],
"outputs": [
{
"name": "firstIndex",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "appendPayloads",
"inputs": [
{
"name": "payloads",
"type": "bytes32[]",
"internalType": "bytes32[]"
},
{
"name": "anchorBlock",
"type": "uint64",
"internalType": "uint64"
},
{
"name": "approvals",
"type": "tuple[]",
"internalType": "struct FinalPqQuorum.Approval[]",
"components": [
{
"name": "signer",
"type": "address",
"internalType": "address"
},
{
"name": "algorithm",
"type": "uint8",
"internalType": "uint8"
},
{
"name": "signature",
"type": "bytes",
"internalType": "bytes"
},
{
"name": "seal",
"type": "bytes",
"internalType": "bytes"
}
]
}
],
"outputs": [
{
"name": "firstIndex",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "bundleAt",
"inputs": [
{
"name": "leafIndex",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "atSize",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "payload",
"type": "bytes32",
"internalType": "bytes32"
},
{
"name": "proof",
"type": "bytes32[]",
"internalType": "bytes32[]"
},
{
"name": "root_",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "configure",
"inputs": [
{
"name": "role",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "k",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "anchorBlock",
"type": "uint64",
"internalType": "uint64"
},
{
"name": "approvals",
"type": "tuple[]",
"internalType": "struct FinalPqQuorum.Approval[]",
"components": [
{
"name": "signer",
"type": "address",
"internalType": "address"
},
{
"name": "algorithm",
"type": "uint8",
"internalType": "uint8"
},
{
"name": "signature",
"type": "bytes",
"internalType": "bytes"
},
{
"name": "seal",
"type": "bytes",
"internalType": "bytes"
}
]
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "head",
"inputs": [],
"outputs": [
{
"name": "root_",
"type": "bytes32",
"internalType": "bytes32"
},
{
"name": "size_",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "indexOf",
"inputs": [
{
"name": "payload",
"type": "bytes32",
"internalType": "bytes32"
}
],
"outputs": [
{
"name": "index",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "found",
"type": "bool",
"internalType": "bool"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "intentLog",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "contract FinalIntentLog"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "nonce",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint64",
"internalType": "uint64"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "onERC1155BatchReceived",
"inputs": [
{
"name": "",
"type": "address",
"internalType": "address"
},
{
"name": "",
"type": "address",
"internalType": "address"
},
{
"name": "",
"type": "uint256[]",
"internalType": "uint256[]"
},
{
"name": "",
"type": "uint256[]",
"internalType": "uint256[]"
},
{
"name": "",
"type": "bytes",
"internalType": "bytes"
}
],
"outputs": [
{
"name": "",
"type": "bytes4",
"internalType": "bytes4"
}
],
"stateMutability": "pure"
},
{
"type": "function",
"name": "onERC1155Received",
"inputs": [
{
"name": "",
"type": "address",
"internalType": "address"
},
{
"name": "",
"type": "address",
"internalType": "address"
},
{
"name": "",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "",
"type": "bytes",
"internalType": "bytes"
}
],
"outputs": [
{
"name": "",
"type": "bytes4",
"internalType": "bytes4"
}
],
"stateMutability": "pure"
},
{
"type": "function",
"name": "onERC721Received",
"inputs": [
{
"name": "",
"type": "address",
"internalType": "address"
},
{
"name": "",
"type": "address",
"internalType": "address"
},
{
"name": "",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "",
"type": "bytes",
"internalType": "bytes"
}
],
"outputs": [
{
"name": "",
"type": "bytes4",
"internalType": "bytes4"
}
],
"stateMutability": "pure"
},
{
"type": "function",
"name": "payloadAt",
"inputs": [
{
"name": "index",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "payloadsBetween",
"inputs": [
{
"name": "from",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "to",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "out",
"type": "bytes32[]",
"internalType": "bytes32[]"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "peaks",
"inputs": [],
"outputs": [
{
"name": "",
"type": "bytes32[]",
"internalType": "bytes32[]"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "peaksAt",
"inputs": [
{
"name": "atSize",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "bag",
"type": "bytes32[]",
"internalType": "bytes32[]"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "proofAt",
"inputs": [
{
"name": "leafIndex",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "atSize",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "proof",
"type": "bytes32[]",
"internalType": "bytes32[]"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "registry",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "contract FinalIdentityRegistry"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "root",
"inputs": [],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "rootAt",
"inputs": [
{
"name": "atSize",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "seed",
"inputs": [
{
"name": "peaks_",
"type": "bytes32[]",
"internalType": "bytes32[]"
},
{
"name": "size_",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "anchorBlock",
"type": "uint64",
"internalType": "uint64"
},
{
"name": "approvals",
"type": "tuple[]",
"internalType": "struct FinalPqQuorum.Approval[]",
"components": [
{
"name": "signer",
"type": "address",
"internalType": "address"
},
{
"name": "algorithm",
"type": "uint8",
"internalType": "uint8"
},
{
"name": "signature",
"type": "bytes",
"internalType": "bytes"
},
{
"name": "seal",
"type": "bytes",
"internalType": "bytes"
}
]
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "seedPayloads",
"inputs": [
{
"name": "payloads",
"type": "bytes32[]",
"internalType": "bytes32[]"
},
{
"name": "anchorBlock",
"type": "uint64",
"internalType": "uint64"
},
{
"name": "approvals",
"type": "tuple[]",
"internalType": "struct FinalPqQuorum.Approval[]",
"components": [
{
"name": "signer",
"type": "address",
"internalType": "address"
},
{
"name": "algorithm",
"type": "uint8",
"internalType": "uint8"
},
{
"name": "signature",
"type": "bytes",
"internalType": "bytes"
},
{
"name": "seal",
"type": "bytes",
"internalType": "bytes"
}
]
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "size",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "sweepAsset",
"inputs": [
{
"name": "kind",
"type": "uint8",
"internalType": "enum SweepKind"
},
{
"name": "asset",
"type": "address",
"internalType": "address"
},
{
"name": "id",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "amount",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "to",
"type": "address",
"internalType": "address"
}
],
"outputs": [
{
"name": "moved",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "sweepableSurplus",
"inputs": [
{
"name": "kind",
"type": "uint8",
"internalType": "enum SweepKind"
},
{
"name": "asset",
"type": "address",
"internalType": "address"
},
{
"name": "id",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "surplus",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "threshold",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "writerRole",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "event",
"name": "AssetSwept",
"inputs": [
{
"name": "kind",
"type": "uint8",
"indexed": true,
"internalType": "enum SweepKind"
},
{
"name": "asset",
"type": "address",
"indexed": true,
"internalType": "address"
},
{
"name": "to",
"type": "address",
"indexed": true,
"internalType": "address"
},
{
"name": "id",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
},
{
"name": "amount",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
}
],
"anonymous": false
},
{
"type": "event",
"name": "BundleAppended",
"inputs": [
{
"name": "index",
"type": "uint256",
"indexed": true,
"internalType": "uint256"
},
{
"name": "payload",
"type": "bytes32",
"indexed": true,
"internalType": "bytes32"
},
{
"name": "root",
"type": "bytes32",
"indexed": false,
"internalType": "bytes32"
},
{
"name": "size",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
}
],
"anonymous": false
},
{
"type": "event",
"name": "LogConfigured",
"inputs": [
{
"name": "writerRole",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
},
{
"name": "threshold",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
}
],
"anonymous": false
},
{
"type": "event",
"name": "Seeded",
"inputs": [
{
"name": "size",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
},
{
"name": "peaks",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
}
],
"anonymous": false
},
{
"type": "event",
"name": "SeededPayloads",
"inputs": [
{
"name": "size",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
}
],
"anonymous": false
},
{
"type": "error",
"name": "AnchorAhead",
"inputs": [
{
"name": "anchorBlock",
"type": "uint64",
"internalType": "uint64"
},
{
"name": "blockNumber",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "AnchorStale",
"inputs": [
{
"name": "anchorBlock",
"type": "uint64",
"internalType": "uint64"
},
{
"name": "blockNumber",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "BadSeal",
"inputs": [
{
"name": "signer",
"type": "address",
"internalType": "address"
}
]
},
{
"type": "error",
"name": "BadSignature",
"inputs": [
{
"name": "signer",
"type": "address",
"internalType": "address"
},
{
"name": "algorithm",
"type": "uint8",
"internalType": "uint8"
}
]
},
{
"type": "error",
"name": "EmptyBatch",
"inputs": []
},
{
"type": "error",
"name": "EmptyBundleLeaves",
"inputs": [
{
"name": "bundleIndex",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "EmptyBundleTree",
"inputs": []
},
{
"type": "error",
"name": "LogNotConfigured",
"inputs": []
},
{
"type": "error",
"name": "MmrEmptyLog",
"inputs": []
},
{
"type": "error",
"name": "MmrIndexOutOfRange",
"inputs": [
{
"name": "index",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "size",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "NotAuthorized",
"inputs": [
{
"name": "caller",
"type": "address",
"internalType": "address"
}
]
},
{
"type": "error",
"name": "NotFresh",
"inputs": []
},
{
"type": "error",
"name": "PeaksMismatch",
"inputs": [
{
"name": "expected",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "given",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "PrecompileUnavailable",
"inputs": [
{
"name": "precompile",
"type": "address",
"internalType": "address"
}
]
},
{
"type": "error",
"name": "ProofShapeMismatch",
"inputs": [
{
"name": "expected",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "walked",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "SignerLacksRole",
"inputs": [
{
"name": "signer",
"type": "address",
"internalType": "address"
},
{
"name": "roleMask",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "SignersNotAscending",
"inputs": [
{
"name": "previous",
"type": "address",
"internalType": "address"
},
{
"name": "next",
"type": "address",
"internalType": "address"
}
]
},
{
"type": "error",
"name": "SizeAhead",
"inputs": [
{
"name": "asked",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "held",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "SweepAboveSurplus",
"inputs": [
{
"name": "asset",
"type": "address",
"internalType": "address"
},
{
"name": "requested",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "surplus",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "SweepDestinationNotAllowed",
"inputs": [
{
"name": "to",
"type": "address",
"internalType": "address"
}
]
},
{
"type": "error",
"name": "SweepTransferFailed",
"inputs": [
{
"name": "asset",
"type": "address",
"internalType": "address"
}
]
},
{
"type": "error",
"name": "SweepUnauthorized",
"inputs": [
{
"name": "caller",
"type": "address",
"internalType": "address"
}
]
},
{
"type": "error",
"name": "SweepZeroAmount",
"inputs": []
},
{
"type": "error",
"name": "TermsLeafCountMismatch",
"inputs": [
{
"name": "termsLeaves",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "bundles",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "ThresholdIsZero",
"inputs": []
},
{
"type": "error",
"name": "ThresholdNotMet",
"inputs": [
{
"name": "valid",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "required",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "ThresholdUnreachable",
"inputs": [
{
"name": "live",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "required",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "WrongAlgorithm",
"inputs": [
{
"name": "signer",
"type": "address",
"internalType": "address"
},
{
"name": "got",
"type": "uint8",
"internalType": "uint8"
},
{
"name": "required",
"type": "uint8",
"internalType": "uint8"
}
]
},
{
"type": "error",
"name": "ZeroBundleRoot",
"inputs": []
},
{
"type": "error",
"name": "ZeroIntentLog",
"inputs": []
},
{
"type": "error",
"name": "ZeroTermsLeaf",
"inputs": [
{
"name": "bundleIndex",
"type": "uint256",
"internalType": "uint256"
}
]
}
]读取合约
字节码 · 11,619 字节
0x6080806040526004361015610012575f80fd5b5f3560e01c90816304fedb2f14611a1357508063150b7a02146119bd5780631a30f0791461199f578063205a094e146119855780632441c09b1461146757806342cde4e81461144a57806348d316ac146113fa57806352a9674b146113c05780635bb8a951146113a257806360a180081461136e57806362984f88146110da5780636ce60417146110a75780636f4ce56a1461107b57806372f56b2c146110415780637b10399914610ffd5780638f7dcfa314610fd9578063949d225d14610fbc57806394bc4e9614610c9b57806396f51f3a146109c8578063affed0e0146109a2578063b19f480514610968578063bc197c81146108d0578063c0131f591461088c578063ca2869a014610866578063cba573581461084a578063cba8bdf71461040f578063ebb3eedb14610363578063ebf0c71714610346578063f23a6e61146102f05763f47f54cb14610166575f80fd5b346102ec5761017436611b47565b9392919082156102dd576001549182156102ce576001600160401b039161028761028d9260025495858716936006549a8b8b6101de8c6101d060405193849260208401968d885260408501526060808501526080840191611e73565b03601f198101835282611be1565b51902060405160208101917fd850f5df47b124511e8e6ec99cf1a0beaf7c6237eff0a31305ce53d85f31267583524660408301523060608301527f5985b2aa0699a556c4b84df321b016abe612f656b53dfdb4741aaa1912f686b460808301528a871660a083015260c082015260c0815261025a60e082611be1565b519020905f54927f00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf61218f565b50611e97565b16906001600160401b031916176002555f5b8181106102b157602084604051908152f35b806102c86102c26001938587611eb5565b35612436565b0161029f565b6382d4481f60e01b5f5260045ffd5b63c2e5347d60e01b5f5260045ffd5b5f80fd5b346102ec5760a03660031901126102ec57610309611a4b565b50610312611a61565b506084356001600160401b0381116102ec57610332903690600401611a8b565b505060405163f23a6e6160e01b8152602090f35b346102ec575f3660031901126102ec576020600754604051908152f35b346102ec5761037136611ab8565b6006548082116103f957508082116103e3576103956103908383611bc7565b611c2d565b91805b8281106103b957604051602080825281906103b590820187611ace565b0390f35b806001915f52600460205260405f20546103dc6103d68584611bc7565b87611c80565b5201610398565b906388c73b2960e01b5f5260045260245260445ffd5b90635b8d5fdb60e11b5f5260045260245260445ffd5b346102ec5760803660031901126102ec576004356001600160401b0381116102ec5761043f903690600401611b01565b6024359061044b611b31565b6064356001600160401b0381116102ec5761046a903690600401611b01565b6040516328305db160e21b81527f00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf6001600160a01b03169290602081600481875afa908115610708575f9161081b575b5080156107b5575b610619575b5050505060065461060a575f82805b6105e657508181036105d157505f8060ff5b60018086831c161461056e575b801561051d578015610509575f19016104e8565b634e487b7160e01b5f52601160045260245ffd5b7f67f9b61bf7b39fd24dd60467083f89ea77979db358db2804069474590a36c035604086868160065581155f14610560575f5b60075582519182526020820152a1005b6105698261206e565b610550565b9061057a838588611eb5565b35156105c2576105bc906105986105908561212a565b948689611eb5565b35835f52600360205260405f2082851c5f5260205260405f20556001831b90611bd4565b906104f5565b634425ca1360e01b5f5260045ffd5b63ecc9b8ed60e01b5f5260045260245260445ffd5b6001808216146105fa575b60011c806104d6565b906106049061212a565b906105f1565b63dc63d81f60e01b5f5260045ffd5b60405160208101906040825261064b81610637606082018a8d611e73565b8a604083015203601f198101835282611be1565b519020833b156102ec5790826001600160401b039593926040519687956322f3f44760e11b875260848701927f405bbda3343b6e69c32fb7eafff8f0a1e55a5ee2ec35458b3abc776b2668195260048901526024880152166044860152608060648601525260a4830160a060048460051b8601010192825f90607e19813603015b8383106107135750505050505091815f818582965003925af18015610708576106f8575b8080806104c7565b5f61070291611be1565b836106f0565b6040513d5f823e3d90fd5b60a3198a8803018552949650929491939092918635828112156102ec5783016001600160a01b0361074382611a77565b16825260208101359160ff83168093036102ec576107a360209282600195858095015261079561078a6107796040850185611f15565b608060408601526080850191611f46565b926060810190611f15565b916060818503910152611f46565b980196019301909188969594926106cc565b5060405163f5778b0360e01b8152602081600481875afa908115610708575f916107ec575b506001600160a01b03163314156104c2565b61080e915060203d602011610814575b6108068183611be1565b810190611ef6565b886107da565b503d6107fc565b61083d915060203d602011610843575b6108358183611be1565b810190611ede565b886104ba565b503d61082b565b346102ec575f3660031901126102ec5760205f54604051908152f35b346102ec5760203660031901126102ec57602061088460043561206e565b604051908152f35b346102ec575f3660031901126102ec576040517f000000000000000000000000c0876d136341091581a489ce7f746692dddf498f6001600160a01b03168152602090f35b346102ec5760a03660031901126102ec576108e9611a4b565b506108f2611a61565b506044356001600160401b0381116102ec57610912903690600401611b01565b50506064356001600160401b0381116102ec57610933903690600401611b01565b50506084356001600160401b0381116102ec57610954903690600401611a8b565b505060405163bc197c8160e01b8152602090f35b346102ec575f3660031901126102ec5760206040517f27c91cbb7cc32319dd47788e8b096cc02ee8ccca641645266d7046769a12fbc38152f35b346102ec575f3660031901126102ec5760206001600160401b0360025416604051908152f35b346102ec5760a03660031901126102ec5760043560048110156102ec576109ed611a61565b90606435906084356001600160a01b03811691604435918381036102ec57610a136126e4565b60405163f5778b0360e01b81526020816004817f00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf6001600160a01b03165afa908115610708575f91610c7c575b508415908115610c58575b50610c4557610a7b838784611ec5565b945f198103610c405750845b80958115610c3157808211610c0a57505f9183610b285750505f80808088885af1610ab061203f565b5015610b15575b610b0157604080519283526020838101869052956001600160a01b0316927f7643c83e539cea2f6bf506545392e52cfd5f917e327efbcd0ba28f29c28d042e9190a4604051908152f35b634e487b7160e01b5f52602160045260245ffd5b6365f4a9ef60e11b5f525f60045260245ffd5b5f92509060018403610b78575060405163a9059cbb60e01b60208201526001600160a01b03909116602482015260448101869052610b7390610b6d81606481016101d0565b87612882565b610ab7565b5f969250905060028303610bbf575050600193610b736040516323b872dd60e01b602082015230602482015285604482015284606482015260648152610b6d608482611be1565b610b739060409692965190637921219560e11b6020830152306024830152866044830152856064830152608482015260a060a48201525f60c482015260c48152610b6d60e482611be1565b632190968160e01b5f9081526001600160a01b038916600452602492909252604452606490fd5b637c2e506f60e11b5f5260045ffd5b610a87565b836315150d4d60e31b5f5260045260245ffd5b6001600160a01b0316851415905080610c72575b87610a6b565b5033841415610c6c565b610c95915060203d602011610814576108068183611be1565b87610a60565b346102ec5760803660031901126102ec57602435600435610cba611b31565b6064356001600160401b0381116102ec57610cd9903690600401611b01565b6040516328305db160e21b81527f00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf6001600160a01b0316939290602081600481885afa908115610708575f91610f9d575b508015610f47575b610df7575b50505082610d79575b7fbfc08a458e488f0e56f7ff4bfe317bed1ba5d3f7ef5a2bda241528695f6fcdf360408385815f558060015582519182526020820152a1005b60206024916040519283809263342f616360e01b82528660048301525afa908115610708575f91610dc5575b5082811015610d40579050633770da3360e11b5f5260045260245260445ffd5b90506020813d602011610def575b81610de060209383611be1565b810103126102ec575183610da5565b3d9150610dd3565b604051602081019086825287604082015260408152610e17606082611be1565b519020843b156102ec5790826001600160401b0394926040519586946322f3f44760e11b865260848601927f27c91cbb7cc32319dd47788e8b096cc02ee8ccca641645266d7046769a12fbc360048801526024870152166044850152608060648501525260a4820160a060048560051b8501010193825f90607e19813603015b838310610ed15750505050505080825f9350038183865af1801561070857610ec1575b8080610d37565b5f610ecb91611be1565b83610eba565b60a3198989030185529496939550919390928635828112156102ec5783016001600160a01b03610f0082611a77565b16825260208101359160ff83168093036102ec57610f3660209282600195858095015261079561078a6107796040850185611f15565b980196019301909187959492610e97565b5060405163f5778b0360e01b8152602081600481885afa908115610708575f91610f7e575b506001600160a01b0316331415610d32565b610f97915060203d602011610814576108068183611be1565b87610f6c565b610fb6915060203d602011610843576108358183611be1565b87610d2a565b346102ec575f3660031901126102ec576020600654604051908152f35b346102ec575f3660031901126102ec57604060075460065482519182526020820152f35b346102ec575f3660031901126102ec576040517f00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf6001600160a01b03168152602090f35b346102ec575f3660031901126102ec5760206040517f405bbda3343b6e69c32fb7eafff8f0a1e55a5ee2ec35458b3abc776b266819528152f35b346102ec5760203660031901126102ec576040611099600435611ffa565b825191825215156020820152f35b346102ec5760203660031901126102ec576103b56110c6600435611f66565b604051918291602083526020830190611ace565b346102ec576110e836611b47565b6040516328305db160e21b81529394937f00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf6001600160a01b03169290602081600481875afa908115610708575f9161134f575b5080156112f9575b6111a6575b5050505060065461060a5781156102dd575f5b82811061118f577f1c295873c1ce4ce2ac720f43d6909e66b931b42e9246b862278eba9624c0bf05602084604051908152a1005b806111a06102c26001938686611eb5565b0161115b565b6040516020810190602082526111c4816101d0604082018b8b611e73565b519020833b156102ec5790826001600160401b039593926040519687956322f3f44760e11b875260848701927f9abdf9961fd14fd177480eccbad16b2d7f231898b2d763c8e8b50364d8b3b17160048901526024880152166044860152608060648601525260a4830160a060048460051b8601010192825f90607e19813603015b8383106112815750505050505091815f818582965003925af1801561070857611271575b808080611148565b5f61127b91611be1565b82611269565b60a3198a8803018552949650929491939092918635828112156102ec5783016001600160a01b036112b182611a77565b16825260208101359160ff83168093036102ec576112e760209282600195858095015261079561078a6107796040850185611f15565b98019601930190918896959492611245565b5060405163f5778b0360e01b8152602081600481875afa908115610708575f91611330575b506001600160a01b0316331415611143565b611349915060203d602011610814576108068183611be1565b8761131e565b611368915060203d602011610843576108358183611be1565b8761113b565b346102ec5760603660031901126102ec5760043560048110156102ec57610884602091611399611a61565b60443591611ec5565b346102ec575f3660031901126102ec576103b56110c6600654611f66565b346102ec575f3660031901126102ec5760206040517fb66ca34dc0d9a9daa6230aee35894330ccfa7e4eaa29a198577eed0b26a412058152f35b346102ec5761140836611ab8565b61142461141e6114188385611c94565b93611bac565b9161206e565b6114406040519384938452606060208501526060840190611ace565b9060408301520390f35b346102ec575f3660031901126102ec576020600154604051908152f35b346102ec5760803660031901126102ec576004356001600160401b0381116102ec57611497903690600401611b01565b906024356001600160401b0381116102ec576114b7903690600401611b01565b6114c2939193611b31565b936064356001600160401b0381116102ec576114e2903690600401611b01565b9583156102dd5783850361196e5760015480156102ce5760029795979693965492600654966040516001600160401b03861660208201528860408201526080606082015261153460a082018c89611e73565b601f19828203016080830152888152602081019060208a60051b820101918c915f5b8c811061190257505050509061157c81611603979695949303601f198101835282611be1565b6020815191012060405160208101917fd850f5df47b124511e8e6ec99cf1a0beaf7c6237eff0a31305ce53d85f31267583524660408301523060608301527f2e1c2ff2f9bb13fd926fe3e8b209f98e6c873bb259534a2148ca355409247cba60808301526001600160401b03871660a083015260c082015260c0815261025a60e082611be1565b506001600160401b03611617818316611e97565b67ffffffffffffffff199092169116176002555f947f000000000000000000000000c0876d136341091581a489ce7f746692dddf498f6001600160a01b03165b838710156118f7578660051b860135601e19873603018112156102ec5786018035906001600160401b0382116102ec57602001908060051b360382136102ec5780156118e4576116a8898587611eb5565b35156118d15760018101808211610509576116c290611c2d565b916116ce8a8688611eb5565b356116d884611c5f565b525f5b82811061185a5750505080511561184b575b8051600181111561181f578060011c90600181169261170f6103908585611bd4565b935f5b84811061179f575060011461172a575b5050506116ed565b5f198201918211610509576117969161174291611c80565b516040516020810191600160f91b83527fc976f483968b324bd57de8efa226478a3634db61776dacd4da866f8fa37c0fd5602183015260418201526041815261178c606182611be1565b5190209183611c80565b52888080611722565b80600191821b6117bc836117b38388611c80565b51921786611c80565b516040519060208201928560f81b84527fc976f483968b324bd57de8efa226478a3634db61776dacd4da866f8fa37c0fd56021840152604183015260618201526061815261180b608182611be1565b5190206118188289611c80565b5201611712565b509661183d6118376001939699989598979497611c5f565b51612436565b019592949194939093611657565b634f297b6160e11b5f5260045ffd5b611865818484611eb5565b35853b156102ec576040519063af6f8c1b60e01b825260048201525f81602481838a5af18015610708576118c1575b506118a0818484611eb5565b35906001810191828211610509576118ba60019387611c80565b52016116db565b5f6118cb91611be1565b8b611894565b886322566cfd60e01b5f5260045260245ffd5b8863c9cdeff560e01b5f5260045260245ffd5b602085604051908152f35b909192939c9e9c601f9e9b9e19838203018452601e198c360301853512156102ec578b85350190602082359201916001600160401b0381116102ec578060051b360383136102ec5761195a6020928392600195611e73565b9601940191019e9c9e9d9a9d919091611556565b8385635b2d642360e11b5f5260045260245260445ffd5b346102ec576103b56110c661199936611ab8565b90611c94565b346102ec5760203660031901126102ec576020610884600435611bac565b346102ec5760803660031901126102ec576119d6611a4b565b506119df611a61565b506064356001600160401b0381116102ec576119ff903690600401611a8b565b5050604051630a85bd0160e11b8152602090f35b346102ec575f3660031901126102ec57807f9abdf9961fd14fd177480eccbad16b2d7f231898b2d763c8e8b50364d8b3b17160209252f35b600435906001600160a01b03821682036102ec57565b602435906001600160a01b03821682036102ec57565b35906001600160a01b03821682036102ec57565b9181601f840112156102ec578235916001600160401b0383116102ec57602083818601950101116102ec57565b60409060031901126102ec576004359060243590565b90602080835192838152019201905f5b818110611aeb5750505090565b8251845260209384019390920191600101611ade565b9181601f840112156102ec578235916001600160401b0383116102ec576020808501948460051b0101116102ec57565b604435906001600160401b03821682036102ec57565b9060606003198301126102ec576004356001600160401b0381116102ec5782611b7291600401611b01565b929092916024356001600160401b03811681036102ec5791604435906001600160401b0382116102ec57611ba891600401611b01565b9091565b600654808210156103e357505f52600460205260405f205490565b9190820391821161050957565b9190820180921161050957565b90601f801991011681019081106001600160401b03821117611c0257604052565b634e487b7160e01b5f52604160045260245ffd5b6001600160401b038111611c025760051b60200190565b90611c3782611c16565b611c446040519182611be1565b8281528092611c55601f1991611c16565b0190602036910137565b805115611c6c5760200190565b634e487b7160e01b5f52603260045260245ffd5b8051821015611c6c5760209160051b010190565b91906006548082116103f957508015611e645780831015611e4e575f198101908082116105095790611cde610390611ccd838718612138565b611cd887821c612151565b90611bd4565b9390915f835f945b611d1057505050508251808203611cfb575050565b63383613b560e01b5f5260045260245260445ffd5b90919293600185188281105f14611d5d578392916001949185925f52600360205260405f20905f5260205260405f2054611d4a828b611c80565b5201945b831c9392918201911c80611ce6565b828196929614611d73575b509060019291611d4e565b839591951b611d828186611bc7565b611d8e61039082612151565b905f9290611d9b81612138565b805b611e01575050505f19820191821161050957611db98282611c80565b5191805b611de1575050600193929181859250611dd6828b611c80565b520194909192611d68565b5f1901918290611dfb90611df58385611c80565b51612922565b92611dbd565b5f190160018083831c1614611e17575b80611d9d565b6001819395825f52600360205260405f2087841c5f5260205260405f2054611e3f8288611c80565b5201946001821b019250611e11565b826388c73b2960e01b5f5260045260245260445ffd5b635bf77f6760e01b5f5260045ffd5b81835290916001600160fb1b0383116102ec5760209260051b809284830137010190565b6001600160401b036001911601906001600160401b03821161050957565b9190811015611c6c5760051b0190565b90611ed092916125a1565b8015611ed95790565b505f90565b908160209103126102ec575180151581036102ec5790565b908160209103126102ec57516001600160a01b03811681036102ec5790565b9035601e19823603018112156102ec5701602081359101916001600160401b0382116102ec5781360383136102ec57565b908060209392818452848401375f828201840152601f01601f1916010190565b90600654808311611fe45750611f7e61039083612151565b915f5f91611f8b81612138565b805b611f975750505050565b5f190160018083831c1614611fad575b80611f8d565b6001819493825f52600360205260405f2085841c5f5260205260405f2054611fd5828a611c80565b5201926001821b019350611fa7565b82635b8d5fdb60e11b5f5260045260245260445ffd5b5f52600560205260405f2054801561201d575f1981019081116105095790600190565b505f905f90565b6001600160401b038111611c0257601f01601f191660200190565b3d15612069573d9061205082612024565b9161205e6040519384611be1565b82523d5f602084013e565b606090565b6006548082116103f957508015611ed95761208b61039082612151565b5f915f9061209881612138565b805b6120dd575050505f198201918211610509576120b68282611c80565b5191805b6120c357505090565b5f19019182906120d790611df58385611c80565b926120ba565b5f190160018083831c16146120f3575b8061209a565b6001819395825f52600360205260405f2087841c5f5260205260405f205461211b8288611c80565b5201946001821b0192506120ed565b5f1981146105095760010190565b90815f925b6121445750565b6001928301921c8061213d565b90815f925b61215d5750565b9160018316019160011c80612156565b356001600160a01b03811681036102ec5790565b3560ff811681036102ec5790565b92939195965f978615612427576001600160401b0316438111612411576102586121b98243611bc7565b116123fb5750604051946020860152602085526121d7604086611be1565b5f955f985b888a10156123d1578960051b840135607e19853603018112156102ec578401976122058961216d565b6001600160a01b0391821691168110156123a557506122238861216d565b976122646020876122338461216d565b604051632e4bfa5160e11b81526001600160a01b039091166004820152602481019190915291829081906044820190565b03816001600160a01b038c165afa908115610708575f91612387575b50156123605760208101600460ff61229783612181565b160361232e576122a889838a612a42565b156122fb57506122b9888289612b87565b156122d257506122ca60019161212a565b9901986121dc565b6122db9061216d565b63c082266360e01b5f9081526001600160a01b0391909116600452602490fd5b61230f61230960ff9361216d565b91612181565b9063bbf82ba360e01b5f5260018060a01b03166004521660245260445ffd5b61233c61230960ff9361216d565b9063587548c360e11b5f5260018060a01b031660045216602452600460445260645ffd5b61236a869161216d565b63ae8bb03960e01b5f5260018060a01b031660045260245260445ffd5b61239f915060203d8111610843576108358183611be1565b5f612280565b6123ae8961216d565b6311641feb60e21b5f9081526004929092526001600160a01b0316602452604490fd5b985095509550505050508083106123e55750565b826305bc216760e51b5f5260045260245260445ffd5b630ed38fd160e41b5f526004524360245260445ffd5b637b51505560e01b5f526004524360245260445ffd5b631fc460bf60e11b5f5260045ffd5b80156105c257600654805f5260046020528160405f2055815f52600560205260405f205415612584575b60405160208101905f82527fb66ca34dc0d9a9daa6230aee35894330ccfa7e4eaa29a198577eed0b26a412056021820152836041820152604181526124a6606182611be1565b5190205f8281527f3617319a054d772f909f7c479a2cebe5066e836a939412e32403c99029b92eff602052604081208290559082905b60018083161461252f575050507f1585fcb2f8b662b0e77609aa657994b280f417bea79b40989d135efaf88405486040600183018060065561251d8161206e565b908160075582519182526020820152a3565b825f52600360205260405f20905f198301908382116105095760019261255e925f5260205260405f2054612922565b91811c920190815f52600360205260405f20835f526020528060405f20559190916124dc565b6001810180821161050957825f52600560205260405f2055612460565b906004821015610b015781156126dd575f928392600181146126b45760021461262c57604051627eeac760e11b6020820190815230602483015260448201929092526125f081606481016101d0565b51915afa6125fc61203f565b9080612620575b15611ed957602081519181808201938492010103126102ec575190565b50602081511015612603565b60405160208101916331a9108f60e11b8352602482015260248152612652604482611be1565b51915afa61265e61203f565b816126a6575b81612679575b501561267557600190565b5f90565b90506020818051810103126102ec57602001516001600160a01b038116908190036102ec5730145f61266a565b905060208151101590612664565b505060405160208101906370a0823160e01b8252306024820152602481526125f0604482611be1565b5050504790565b6040516328305db160e21b81527f00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf6001600160a01b031690602081600481855afa908115610708575f91612863575b50158061280e575b61280b5760405163e14c465b60e01b8152602081600481855afa908115610708575f916127d7575b50604051632e4bfa5160e11b815233600482015260248101919091529060209082908180604481015b03915afa908115610708575f916127b8575b506127b65763321cbc0960e21b5f523360045260245ffd5b565b6127d1915060203d602011610843576108358183611be1565b5f61279e565b90506020813d602011612803575b816127f260209383611be1565b810103126102ec575161278c612763565b3d91506127e5565b50565b5060405163f5778b0360e01b8152602081600481855afa908115610708575f91612844575b506001600160a01b0316331461273b565b61285d915060203d602011610814576108068183611be1565b5f612833565b61287c915060203d602011610843576108358183611be1565b5f612733565b90813b15612901575f816020829351910182855af161289f61203f565b90159081156128d1575b506128b15750565b6365f4a9ef60e11b5f9081526001600160a01b0391909116600452602490fd5b80518015159250826128e6575b50505f6128a9565b6128f99250602080918301019101611ede565b155f806128de565b506365f4a9ef60e11b5f9081526001600160a01b0391909116600452602490fd5b90604051906020820192600160f81b84527fb66ca34dc0d9a9daa6230aee35894330ccfa7e4eaa29a198577eed0b26a4120560218401526041830152606182015260618152612972608182611be1565b51902090565b6020818303126102ec578051906001600160401b0382116102ec570181601f820112156102ec578051906129ab82612024565b926129b96040519485611be1565b828452602083830101116102ec57815f9260208093018386015e8301015290565b903590601e19813603018212156102ec57018035906001600160401b0382116102ec576020019181360383136102ec57565b929192612a1882612024565b91612a266040519384611be1565b8294818452818301116102ec578281602093845f960137010152565b9160208201600460ff612a5483612181565b1614612b065760ff612a67600592612181565b1614612a74575050505f90565b5f612a7e8361216d565b604051639e5adaeb60e01b81526001600160a01b0391821660048201529485916024918391165afa91821561070857612ad7935f93612ada575b50612aca816040612ad19301906129da565b3691612a0c565b91612ce7565b90565b612ad1919350612afe612aca913d805f833e612af68183611be1565b810190612978565b939150612ab8565b505f612b118361216d565b60405163b7af85d760e01b81526001600160a01b0391821660048201529485916024918391165afa91821561070857612ad7935f93612b63575b50612aca816040612b5d9301906129da565b91612c25565b612b5d919350612b7f612aca913d805f833e612af68183611be1565b939150612b4b565b90915f612b938461216d565b60405163ad84ad1360e01b81526001600160a01b0391821660048201529384916024918391165afa918215610708575f92612c09575b508151158015612bf3575b612bec57612ad1612aca846060612ad79601906129da565b5050505f90565b50612c0160608401846129da565b905015612bd4565b612c1e9192503d805f833e612af68183611be1565b905f612bc9565b610a20815114801590612cda575b612bec576020612c865f948286958160405195869481808701998051918291018b5e8601908282018b8152815193849201905e010190878252805192839101825e0185815203601f198101835282611be1565b51906102045afa612c9561203f565b81612cce575b81612ca4575090565b9050602081519101519060208110612cbd575b50151590565b5f199060200360031b1b165f612cb7565b80516020149150612c9b565b5061121383511415612c33565b6040815114801590612d56575b612bec576020612d475f948286958160405195869481808701998051918291018b5e8601908282018b8152815193849201905e010190878252805192839101825e0185815203601f198101835282611be1565b51906102055afa612c9561203f565b5061746083511415612cf456
没有 CBOR 元数据尾部 — 此字节码在关闭 cbor_metadata 的情况下构建,这是我们自己的合约为保持 CREATE2 地址不变而固定的设置。
反汇编 (前 4,000 条操作)
| pc | op | 操作数 |
|---|---|---|
| 0000 | PUSH1 | 0x80 |
| 0002 | DUP1 | |
| 0003 | PUSH1 | 0x40 |
| 0005 | MSTORE | |
| 0006 | PUSH1 | 0x04 |
| 0008 | CALLDATASIZE | |
| 0009 | LT | |
| 000a | ISZERO | |
| 000b | PUSH2 | 0x0012 |
| 000e | JUMPI | |
| 000f | PUSH0 | |
| 0010 | DUP1 | |
| 0011 | REVERT | |
| 0012 | JUMPDEST | |
| 0013 | PUSH0 | |
| 0014 | CALLDATALOAD | |
| 0015 | PUSH1 | 0xe0 |
| 0017 | SHR | |
| 0018 | SWAP1 | |
| 0019 | DUP2 | |
| 001a | PUSH4 | 0x04fedb2f |
| 001f | EQ | |
| 0020 | PUSH2 | 0x1a13 |
| 0023 | JUMPI | |
| 0024 | POP | |
| 0025 | DUP1 | |
| 0026 | PUSH4 | 0x150b7a02 |
| 002b | EQ | |
| 002c | PUSH2 | 0x19bd |
| 002f | JUMPI | |
| 0030 | DUP1 | |
| 0031 | PUSH4 | 0x1a30f079 |
| 0036 | EQ | |
| 0037 | PUSH2 | 0x199f |
| 003a | JUMPI | |
| 003b | DUP1 | |
| 003c | PUSH4 | 0x205a094e |
| 0041 | EQ | |
| 0042 | PUSH2 | 0x1985 |
| 0045 | JUMPI | |
| 0046 | DUP1 | |
| 0047 | PUSH4 | 0x2441c09b |
| 004c | EQ | |
| 004d | PUSH2 | 0x1467 |
| 0050 | JUMPI | |
| 0051 | DUP1 | |
| 0052 | PUSH4 | 0x42cde4e8 |
| 0057 | EQ | |
| 0058 | PUSH2 | 0x144a |
| 005b | JUMPI | |
| 005c | DUP1 | |
| 005d | PUSH4 | 0x48d316ac |
| 0062 | EQ | |
| 0063 | PUSH2 | 0x13fa |
| 0066 | JUMPI | |
| 0067 | DUP1 | |
| 0068 | PUSH4 | 0x52a9674b |
| 006d | EQ | |
| 006e | PUSH2 | 0x13c0 |
| 0071 | JUMPI | |
| 0072 | DUP1 | |
| 0073 | PUSH4 | 0x5bb8a951 |
| 0078 | EQ | |
| 0079 | PUSH2 | 0x13a2 |
| 007c | JUMPI | |
| 007d | DUP1 | |
| 007e | PUSH4 | 0x60a18008 |
| 0083 | EQ | |
| 0084 | PUSH2 | 0x136e |
| 0087 | JUMPI | |
| 0088 | DUP1 | |
| 0089 | PUSH4 | 0x62984f88 |
| 008e | EQ | |
| 008f | PUSH2 | 0x10da |
| 0092 | JUMPI | |
| 0093 | DUP1 | |
| 0094 | PUSH4 | 0x6ce60417 |
| 0099 | EQ | |
| 009a | PUSH2 | 0x10a7 |
| 009d | JUMPI | |
| 009e | DUP1 | |
| 009f | PUSH4 | 0x6f4ce56a |
| 00a4 | EQ | |
| 00a5 | PUSH2 | 0x107b |
| 00a8 | JUMPI | |
| 00a9 | DUP1 | |
| 00aa | PUSH4 | 0x72f56b2c |
| 00af | EQ | |
| 00b0 | PUSH2 | 0x1041 |
| 00b3 | JUMPI | |
| 00b4 | DUP1 | |
| 00b5 | PUSH4 | 0x7b103999 |
| 00ba | EQ | |
| 00bb | PUSH2 | 0x0ffd |
| 00be | JUMPI | |
| 00bf | DUP1 | |
| 00c0 | PUSH4 | 0x8f7dcfa3 |
| 00c5 | EQ | |
| 00c6 | PUSH2 | 0x0fd9 |
| 00c9 | JUMPI | |
| 00ca | DUP1 | |
| 00cb | PUSH4 | 0x949d225d |
| 00d0 | EQ | |
| 00d1 | PUSH2 | 0x0fbc |
| 00d4 | JUMPI | |
| 00d5 | DUP1 | |
| 00d6 | PUSH4 | 0x94bc4e96 |
| 00db | EQ | |
| 00dc | PUSH2 | 0x0c9b |
| 00df | JUMPI | |
| 00e0 | DUP1 | |
| 00e1 | PUSH4 | 0x96f51f3a |
| 00e6 | EQ | |
| 00e7 | PUSH2 | 0x09c8 |
| 00ea | JUMPI | |
| 00eb | DUP1 | |
| 00ec | PUSH4 | 0xaffed0e0 |
| 00f1 | EQ | |
| 00f2 | PUSH2 | 0x09a2 |
| 00f5 | JUMPI | |
| 00f6 | DUP1 | |
| 00f7 | PUSH4 | 0xb19f4805 |
| 00fc | EQ | |
| 00fd | PUSH2 | 0x0968 |
| 0100 | JUMPI | |
| 0101 | DUP1 | |
| 0102 | PUSH4 | 0xbc197c81 |
| 0107 | EQ | |
| 0108 | PUSH2 | 0x08d0 |
| 010b | JUMPI | |
| 010c | DUP1 | |
| 010d | PUSH4 | 0xc0131f59 |
| 0112 | EQ | |
| 0113 | PUSH2 | 0x088c |
| 0116 | JUMPI | |
| 0117 | DUP1 | |
| 0118 | PUSH4 | 0xca2869a0 |
| 011d | EQ | |
| 011e | PUSH2 | 0x0866 |
| 0121 | JUMPI | |
| 0122 | DUP1 | |
| 0123 | PUSH4 | 0xcba57358 |
| 0128 | EQ | |
| 0129 | PUSH2 | 0x084a |
| 012c | JUMPI | |
| 012d | DUP1 | |
| 012e | PUSH4 | 0xcba8bdf7 |
| 0133 | EQ | |
| 0134 | PUSH2 | 0x040f |
| 0137 | JUMPI | |
| 0138 | DUP1 | |
| 0139 | PUSH4 | 0xebb3eedb |
| 013e | EQ | |
| 013f | PUSH2 | 0x0363 |
| 0142 | JUMPI | |
| 0143 | DUP1 | |
| 0144 | PUSH4 | 0xebf0c717 |
| 0149 | EQ | |
| 014a | PUSH2 | 0x0346 |
| 014d | JUMPI | |
| 014e | DUP1 | |
| 014f | PUSH4 | 0xf23a6e61 |
| 0154 | EQ | |
| 0155 | PUSH2 | 0x02f0 |
| 0158 | JUMPI | |
| 0159 | PUSH4 | 0xf47f54cb |
| 015e | EQ | |
| 015f | PUSH2 | 0x0166 |
| 0162 | JUMPI | |
| 0163 | PUSH0 | |
| 0164 | DUP1 | |
| 0165 | REVERT | |
| 0166 | JUMPDEST | |
| 0167 | CALLVALUE | |
| 0168 | PUSH2 | 0x02ec |
| 016b | JUMPI | |
| 016c | PUSH2 | 0x0174 |
| 016f | CALLDATASIZE | |
| 0170 | PUSH2 | 0x1b47 |
| 0173 | JUMP | |
| 0174 | JUMPDEST | |
| 0175 | SWAP4 | |
| 0176 | SWAP3 | |
| 0177 | SWAP2 | |
| 0178 | SWAP1 | |
| 0179 | DUP3 | |
| 017a | ISZERO | |
| 017b | PUSH2 | 0x02dd |
| 017e | JUMPI | |
| 017f | PUSH1 | 0x01 |
| 0181 | SLOAD | |
| 0182 | SWAP2 | |
| 0183 | DUP3 | |
| 0184 | ISZERO | |
| 0185 | PUSH2 | 0x02ce |
| 0188 | JUMPI | |
| 0189 | PUSH1 | 0x01 |
| 018b | PUSH1 | 0x01 |
| 018d | PUSH1 | 0x40 |
| 018f | SHL | |
| 0190 | SUB | |
| 0191 | SWAP2 | |
| 0192 | PUSH2 | 0x0287 |
| 0195 | PUSH2 | 0x028d |
| 0198 | SWAP3 | |
| 0199 | PUSH1 | 0x02 |
| 019b | SLOAD | |
| 019c | SWAP6 | |
| 019d | DUP6 | |
| 019e | DUP8 | |
| 019f | AND | |
| 01a0 | SWAP4 | |
| 01a1 | PUSH1 | 0x06 |
| 01a3 | SLOAD | |
| 01a4 | SWAP11 | |
| 01a5 | DUP12 | |
| 01a6 | DUP12 | |
| 01a7 | PUSH2 | 0x01de |
| 01aa | DUP13 | |
| 01ab | PUSH2 | 0x01d0 |
| 01ae | PUSH1 | 0x40 |
| 01b0 | MLOAD | |
| 01b1 | SWAP4 | |
| 01b2 | DUP5 | |
| 01b3 | SWAP3 | |
| 01b4 | PUSH1 | 0x20 |
| 01b6 | DUP5 | |
| 01b7 | ADD | |
| 01b8 | SWAP7 | |
| 01b9 | DUP14 | |
| 01ba | DUP9 | |
| 01bb | MSTORE | |
| 01bc | PUSH1 | 0x40 |
| 01be | DUP6 | |
| 01bf | ADD | |
| 01c0 | MSTORE | |
| 01c1 | PUSH1 | 0x60 |
| 01c3 | DUP1 | |
| 01c4 | DUP6 | |
| 01c5 | ADD | |
| 01c6 | MSTORE | |
| 01c7 | PUSH1 | 0x80 |
| 01c9 | DUP5 | |
| 01ca | ADD | |
| 01cb | SWAP2 | |
| 01cc | PUSH2 | 0x1e73 |
| 01cf | JUMP | |
| 01d0 | JUMPDEST | |
| 01d1 | SUB | |
| 01d2 | PUSH1 | 0x1f |
| 01d4 | NOT | |
| 01d5 | DUP2 | |
| 01d6 | ADD | |
| 01d7 | DUP4 | |
| 01d8 | MSTORE | |
| 01d9 | DUP3 | |
| 01da | PUSH2 | 0x1be1 |
| 01dd | JUMP | |
| 01de | JUMPDEST | |
| 01df | MLOAD | |
| 01e0 | SWAP1 | |
| 01e1 | KECCAK256 | |
| 01e2 | PUSH1 | 0x40 |
| 01e4 | MLOAD | |
| 01e5 | PUSH1 | 0x20 |
| 01e7 | DUP2 | |
| 01e8 | ADD | |
| 01e9 | SWAP2 | |
| 01ea | PUSH32 | 0xd850f5df47b124511e8e6ec99cf1a0beaf7c6237eff0a31305ce53d85f312675 |
| 020b | DUP4 | |
| 020c | MSTORE | |
| 020d | CHAINID | |
| 020e | PUSH1 | 0x40 |
| 0210 | DUP4 | |
| 0211 | ADD | |
| 0212 | MSTORE | |
| 0213 | ADDRESS | |
| 0214 | PUSH1 | 0x60 |
| 0216 | DUP4 | |
| 0217 | ADD | |
| 0218 | MSTORE | |
| 0219 | PUSH32 | 0x5985b2aa0699a556c4b84df321b016abe612f656b53dfdb4741aaa1912f686b4 |
| 023a | PUSH1 | 0x80 |
| 023c | DUP4 | |
| 023d | ADD | |
| 023e | MSTORE | |
| 023f | DUP11 | |
| 0240 | DUP8 | |
| 0241 | AND | |
| 0242 | PUSH1 | 0xa0 |
| 0244 | DUP4 | |
| 0245 | ADD | |
| 0246 | MSTORE | |
| 0247 | PUSH1 | 0xc0 |
| 0249 | DUP3 | |
| 024a | ADD | |
| 024b | MSTORE | |
| 024c | PUSH1 | 0xc0 |
| 024e | DUP2 | |
| 024f | MSTORE | |
| 0250 | PUSH2 | 0x025a |
| 0253 | PUSH1 | 0xe0 |
| 0255 | DUP3 | |
| 0256 | PUSH2 | 0x1be1 |
| 0259 | JUMP | |
| 025a | JUMPDEST | |
| 025b | MLOAD | |
| 025c | SWAP1 | |
| 025d | KECCAK256 | |
| 025e | SWAP1 | |
| 025f | PUSH0 | |
| 0260 | SLOAD | |
| 0261 | SWAP3 | |
| 0262 | PUSH32 | 0x00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf |
| 0283 | PUSH2 | 0x218f |
| 0286 | JUMP | |
| 0287 | JUMPDEST | |
| 0288 | POP | |
| 0289 | PUSH2 | 0x1e97 |
| 028c | JUMP | |
| 028d | JUMPDEST | |
| 028e | AND | |
| 028f | SWAP1 | |
| 0290 | PUSH1 | 0x01 |
| 0292 | PUSH1 | 0x01 |
| 0294 | PUSH1 | 0x40 |
| 0296 | SHL | |
| 0297 | SUB | |
| 0298 | NOT | |
| 0299 | AND | |
| 029a | OR | |
| 029b | PUSH1 | 0x02 |
| 029d | SSTORE | |
| 029e | PUSH0 | |
| 029f | JUMPDEST | |
| 02a0 | DUP2 | |
| 02a1 | DUP2 | |
| 02a2 | LT | |
| 02a3 | PUSH2 | 0x02b1 |
| 02a6 | JUMPI | |
| 02a7 | PUSH1 | 0x20 |
| 02a9 | DUP5 | |
| 02aa | PUSH1 | 0x40 |
| 02ac | MLOAD | |
| 02ad | SWAP1 | |
| 02ae | DUP2 | |
| 02af | MSTORE | |
| 02b0 | RETURN | |
| 02b1 | JUMPDEST | |
| 02b2 | DUP1 | |
| 02b3 | PUSH2 | 0x02c8 |
| 02b6 | PUSH2 | 0x02c2 |
| 02b9 | PUSH1 | 0x01 |
| 02bb | SWAP4 | |
| 02bc | DUP6 | |
| 02bd | DUP8 | |
| 02be | PUSH2 | 0x1eb5 |
| 02c1 | JUMP | |
| 02c2 | JUMPDEST | |
| 02c3 | CALLDATALOAD | |
| 02c4 | PUSH2 | 0x2436 |
| 02c7 | JUMP | |
| 02c8 | JUMPDEST | |
| 02c9 | ADD | |
| 02ca | PUSH2 | 0x029f |
| 02cd | JUMP | |
| 02ce | JUMPDEST | |
| 02cf | PUSH4 | 0x82d4481f |
| 02d4 | PUSH1 | 0xe0 |
| 02d6 | SHL | |
| 02d7 | PUSH0 | |
| 02d8 | MSTORE | |
| 02d9 | PUSH1 | 0x04 |
| 02db | PUSH0 | |
| 02dc | REVERT | |
| 02dd | JUMPDEST | |
| 02de | PUSH4 | 0xc2e5347d |
| 02e3 | PUSH1 | 0xe0 |
| 02e5 | SHL | |
| 02e6 | PUSH0 | |
| 02e7 | MSTORE | |
| 02e8 | PUSH1 | 0x04 |
| 02ea | PUSH0 | |
| 02eb | REVERT | |
| 02ec | JUMPDEST | |
| 02ed | PUSH0 | |
| 02ee | DUP1 | |
| 02ef | REVERT | |
| 02f0 | JUMPDEST | |
| 02f1 | CALLVALUE | |
| 02f2 | PUSH2 | 0x02ec |
| 02f5 | JUMPI | |
| 02f6 | PUSH1 | 0xa0 |
| 02f8 | CALLDATASIZE | |
| 02f9 | PUSH1 | 0x03 |
| 02fb | NOT | |
| 02fc | ADD | |
| 02fd | SLT | |
| 02fe | PUSH2 | 0x02ec |
| 0301 | JUMPI | |
| 0302 | PUSH2 | 0x0309 |
| 0305 | PUSH2 | 0x1a4b |
| 0308 | JUMP | |
| 0309 | JUMPDEST | |
| 030a | POP | |
| 030b | PUSH2 | 0x0312 |
| 030e | PUSH2 | 0x1a61 |
| 0311 | JUMP | |
| 0312 | JUMPDEST | |
| 0313 | POP | |
| 0314 | PUSH1 | 0x84 |
| 0316 | CALLDATALOAD | |
| 0317 | PUSH1 | 0x01 |
| 0319 | PUSH1 | 0x01 |
| 031b | PUSH1 | 0x40 |
| 031d | SHL | |
| 031e | SUB | |
| 031f | DUP2 | |
| 0320 | GT | |
| 0321 | PUSH2 | 0x02ec |
| 0324 | JUMPI | |
| 0325 | PUSH2 | 0x0332 |
| 0328 | SWAP1 | |
| 0329 | CALLDATASIZE | |
| 032a | SWAP1 | |
| 032b | PUSH1 | 0x04 |
| 032d | ADD | |
| 032e | PUSH2 | 0x1a8b |
| 0331 | JUMP | |
| 0332 | JUMPDEST | |
| 0333 | POP | |
| 0334 | POP | |
| 0335 | PUSH1 | 0x40 |
| 0337 | MLOAD | |
| 0338 | PUSH4 | 0xf23a6e61 |
| 033d | PUSH1 | 0xe0 |
| 033f | SHL | |
| 0340 | DUP2 | |
| 0341 | MSTORE | |
| 0342 | PUSH1 | 0x20 |
| 0344 | SWAP1 | |
| 0345 | RETURN | |
| 0346 | JUMPDEST | |
| 0347 | CALLVALUE | |
| 0348 | PUSH2 | 0x02ec |
| 034b | JUMPI | |
| 034c | PUSH0 | |
| 034d | CALLDATASIZE | |
| 034e | PUSH1 | 0x03 |
| 0350 | NOT | |
| 0351 | ADD | |
| 0352 | SLT | |
| 0353 | PUSH2 | 0x02ec |
| 0356 | JUMPI | |
| 0357 | PUSH1 | 0x20 |
| 0359 | PUSH1 | 0x07 |
| 035b | SLOAD | |
| 035c | PUSH1 | 0x40 |
| 035e | MLOAD | |
| 035f | SWAP1 | |
| 0360 | DUP2 | |
| 0361 | MSTORE | |
| 0362 | RETURN | |
| 0363 | JUMPDEST | |
| 0364 | CALLVALUE | |
| 0365 | PUSH2 | 0x02ec |
| 0368 | JUMPI | |
| 0369 | PUSH2 | 0x0371 |
| 036c | CALLDATASIZE | |
| 036d | PUSH2 | 0x1ab8 |
| 0370 | JUMP | |
| 0371 | JUMPDEST | |
| 0372 | PUSH1 | 0x06 |
| 0374 | SLOAD | |
| 0375 | DUP1 | |
| 0376 | DUP3 | |
| 0377 | GT | |
| 0378 | PUSH2 | 0x03f9 |
| 037b | JUMPI | |
| 037c | POP | |
| 037d | DUP1 | |
| 037e | DUP3 | |
| 037f | GT | |
| 0380 | PUSH2 | 0x03e3 |
| 0383 | JUMPI | |
| 0384 | PUSH2 | 0x0395 |
| 0387 | PUSH2 | 0x0390 |
| 038a | DUP4 | |
| 038b | DUP4 | |
| 038c | PUSH2 | 0x1bc7 |
| 038f | JUMP | |
| 0390 | JUMPDEST | |
| 0391 | PUSH2 | 0x1c2d |
| 0394 | JUMP | |
| 0395 | JUMPDEST | |
| 0396 | SWAP2 | |
| 0397 | DUP1 | |
| 0398 | JUMPDEST | |
| 0399 | DUP3 | |
| 039a | DUP2 | |
| 039b | LT | |
| 039c | PUSH2 | 0x03b9 |
| 039f | JUMPI | |
| 03a0 | PUSH1 | 0x40 |
| 03a2 | MLOAD | |
| 03a3 | PUSH1 | 0x20 |
| 03a5 | DUP1 | |
| 03a6 | DUP3 | |
| 03a7 | MSTORE | |
| 03a8 | DUP2 | |
| 03a9 | SWAP1 | |
| 03aa | PUSH2 | 0x03b5 |
| 03ad | SWAP1 | |
| 03ae | DUP3 | |
| 03af | ADD | |
| 03b0 | DUP8 | |
| 03b1 | PUSH2 | 0x1ace |
| 03b4 | JUMP | |
| 03b5 | JUMPDEST | |
| 03b6 | SUB | |
| 03b7 | SWAP1 | |
| 03b8 | RETURN | |
| 03b9 | JUMPDEST | |
| 03ba | DUP1 | |
| 03bb | PUSH1 | 0x01 |
| 03bd | SWAP2 | |
| 03be | PUSH0 | |
| 03bf | MSTORE | |
| 03c0 | PUSH1 | 0x04 |
| 03c2 | PUSH1 | 0x20 |
| 03c4 | MSTORE | |
| 03c5 | PUSH1 | 0x40 |
| 03c7 | PUSH0 | |
| 03c8 | KECCAK256 | |
| 03c9 | SLOAD | |
| 03ca | PUSH2 | 0x03dc |
| 03cd | PUSH2 | 0x03d6 |
| 03d0 | DUP6 | |
| 03d1 | DUP5 | |
| 03d2 | PUSH2 | 0x1bc7 |
| 03d5 | JUMP | |
| 03d6 | JUMPDEST | |
| 03d7 | DUP8 | |
| 03d8 | PUSH2 | 0x1c80 |
| 03db | JUMP | |
| 03dc | JUMPDEST | |
| 03dd | MSTORE | |
| 03de | ADD | |
| 03df | PUSH2 | 0x0398 |
| 03e2 | JUMP | |
| 03e3 | JUMPDEST | |
| 03e4 | SWAP1 | |
| 03e5 | PUSH4 | 0x88c73b29 |
| 03ea | PUSH1 | 0xe0 |
| 03ec | SHL | |
| 03ed | PUSH0 | |
| 03ee | MSTORE | |
| 03ef | PUSH1 | 0x04 |
| 03f1 | MSTORE | |
| 03f2 | PUSH1 | 0x24 |
| 03f4 | MSTORE | |
| 03f5 | PUSH1 | 0x44 |
| 03f7 | PUSH0 | |
| 03f8 | REVERT | |
| 03f9 | JUMPDEST | |
| 03fa | SWAP1 | |
| 03fb | PUSH4 | 0x5b8d5fdb |
| 0400 | PUSH1 | 0xe1 |
| 0402 | SHL | |
| 0403 | PUSH0 | |
| 0404 | MSTORE | |
| 0405 | PUSH1 | 0x04 |
| 0407 | MSTORE | |
| 0408 | PUSH1 | 0x24 |
| 040a | MSTORE | |
| 040b | PUSH1 | 0x44 |
| 040d | PUSH0 | |
| 040e | REVERT | |
| 040f | JUMPDEST | |
| 0410 | CALLVALUE | |
| 0411 | PUSH2 | 0x02ec |
| 0414 | JUMPI | |
| 0415 | PUSH1 | 0x80 |
| 0417 | CALLDATASIZE | |
| 0418 | PUSH1 | 0x03 |
| 041a | NOT | |
| 041b | ADD | |
| 041c | SLT | |
| 041d | PUSH2 | 0x02ec |
| 0420 | JUMPI | |
| 0421 | PUSH1 | 0x04 |
| 0423 | CALLDATALOAD | |
| 0424 | PUSH1 | 0x01 |
| 0426 | PUSH1 | 0x01 |
| 0428 | PUSH1 | 0x40 |
| 042a | SHL | |
| 042b | SUB | |
| 042c | DUP2 | |
| 042d | GT | |
| 042e | PUSH2 | 0x02ec |
| 0431 | JUMPI | |
| 0432 | PUSH2 | 0x043f |
| 0435 | SWAP1 | |
| 0436 | CALLDATASIZE | |
| 0437 | SWAP1 | |
| 0438 | PUSH1 | 0x04 |
| 043a | ADD | |
| 043b | PUSH2 | 0x1b01 |
| 043e | JUMP | |
| 043f | JUMPDEST | |
| 0440 | PUSH1 | 0x24 |
| 0442 | CALLDATALOAD | |
| 0443 | SWAP1 | |
| 0444 | PUSH2 | 0x044b |
| 0447 | PUSH2 | 0x1b31 |
| 044a | JUMP | |
| 044b | JUMPDEST | |
| 044c | PUSH1 | 0x64 |
| 044e | CALLDATALOAD | |
| 044f | PUSH1 | 0x01 |
| 0451 | PUSH1 | 0x01 |
| 0453 | PUSH1 | 0x40 |
| 0455 | SHL | |
| 0456 | SUB | |
| 0457 | DUP2 | |
| 0458 | GT | |
| 0459 | PUSH2 | 0x02ec |
| 045c | JUMPI | |
| 045d | PUSH2 | 0x046a |
| 0460 | SWAP1 | |
| 0461 | CALLDATASIZE | |
| 0462 | SWAP1 | |
| 0463 | PUSH1 | 0x04 |
| 0465 | ADD | |
| 0466 | PUSH2 | 0x1b01 |
| 0469 | JUMP | |
| 046a | JUMPDEST | |
| 046b | PUSH1 | 0x40 |
| 046d | MLOAD | |
| 046e | PUSH4 | 0x28305db1 |
| 0473 | PUSH1 | 0xe2 |
| 0475 | SHL | |
| 0476 | DUP2 | |
| 0477 | MSTORE | |
| 0478 | PUSH32 | 0x00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf |
| 0499 | PUSH1 | 0x01 |
| 049b | PUSH1 | 0x01 |
| 049d | PUSH1 | 0xa0 |
| 049f | SHL | |
| 04a0 | SUB | |
| 04a1 | AND | |
| 04a2 | SWAP3 | |
| 04a3 | SWAP1 | |
| 04a4 | PUSH1 | 0x20 |
| 04a6 | DUP2 | |
| 04a7 | PUSH1 | 0x04 |
| 04a9 | DUP2 | |
| 04aa | DUP8 | |
| 04ab | GAS | |
| 04ac | STATICCALL | |
| 04ad | SWAP1 | |
| 04ae | DUP2 | |
| 04af | ISZERO | |
| 04b0 | PUSH2 | 0x0708 |
| 04b3 | JUMPI | |
| 04b4 | PUSH0 | |
| 04b5 | SWAP2 | |
| 04b6 | PUSH2 | 0x081b |
| 04b9 | JUMPI | |
| 04ba | JUMPDEST | |
| 04bb | POP | |
| 04bc | DUP1 | |
| 04bd | ISZERO | |
| 04be | PUSH2 | 0x07b5 |
| 04c1 | JUMPI | |
| 04c2 | JUMPDEST | |
| 04c3 | PUSH2 | 0x0619 |
| 04c6 | JUMPI | |
| 04c7 | JUMPDEST | |
| 04c8 | POP | |
| 04c9 | POP | |
| 04ca | POP | |
| 04cb | POP | |
| 04cc | PUSH1 | 0x06 |
| 04ce | SLOAD | |
| 04cf | PUSH2 | 0x060a |
| 04d2 | JUMPI | |
| 04d3 | PUSH0 | |
| 04d4 | DUP3 | |
| 04d5 | DUP1 | |
| 04d6 | JUMPDEST | |
| 04d7 | PUSH2 | 0x05e6 |
| 04da | JUMPI | |
| 04db | POP | |
| 04dc | DUP2 | |
| 04dd | DUP2 | |
| 04de | SUB | |
| 04df | PUSH2 | 0x05d1 |
| 04e2 | JUMPI | |
| 04e3 | POP | |
| 04e4 | PUSH0 | |
| 04e5 | DUP1 | |
| 04e6 | PUSH1 | 0xff |
| 04e8 | JUMPDEST | |
| 04e9 | PUSH1 | 0x01 |
| 04eb | DUP1 | |
| 04ec | DUP7 | |
| 04ed | DUP4 | |
| 04ee | SHR | |
| 04ef | AND | |
| 04f0 | EQ | |
| 04f1 | PUSH2 | 0x056e |
| 04f4 | JUMPI | |
| 04f5 | JUMPDEST | |
| 04f6 | DUP1 | |
| 04f7 | ISZERO | |
| 04f8 | PUSH2 | 0x051d |
| 04fb | JUMPI | |
| 04fc | DUP1 | |
| 04fd | ISZERO | |
| 04fe | PUSH2 | 0x0509 |
| 0501 | JUMPI | |
| 0502 | PUSH0 | |
| 0503 | NOT | |
| 0504 | ADD | |
| 0505 | PUSH2 | 0x04e8 |
| 0508 | JUMP | |
| 0509 | JUMPDEST | |
| 050a | PUSH4 | 0x4e487b71 |
| 050f | PUSH1 | 0xe0 |
| 0511 | SHL | |
| 0512 | PUSH0 | |
| 0513 | MSTORE | |
| 0514 | PUSH1 | 0x11 |
| 0516 | PUSH1 | 0x04 |
| 0518 | MSTORE | |
| 0519 | PUSH1 | 0x24 |
| 051b | PUSH0 | |
| 051c | REVERT | |
| 051d | JUMPDEST | |
| 051e | PUSH32 | 0x67f9b61bf7b39fd24dd60467083f89ea77979db358db2804069474590a36c035 |
| 053f | PUSH1 | 0x40 |
| 0541 | DUP7 | |
| 0542 | DUP7 | |
| 0543 | DUP2 | |
| 0544 | PUSH1 | 0x06 |
| 0546 | SSTORE | |
| 0547 | DUP2 | |
| 0548 | ISZERO | |
| 0549 | PUSH0 | |
| 054a | EQ | |
| 054b | PUSH2 | 0x0560 |
| 054e | JUMPI | |
| 054f | PUSH0 | |
| 0550 | JUMPDEST | |
| 0551 | PUSH1 | 0x07 |
| 0553 | SSTORE | |
| 0554 | DUP3 | |
| 0555 | MLOAD | |
| 0556 | SWAP2 | |
| 0557 | DUP3 | |
| 0558 | MSTORE | |
| 0559 | PUSH1 | 0x20 |
| 055b | DUP3 | |
| 055c | ADD | |
| 055d | MSTORE | |
| 055e | LOG1 | |
| 055f | STOP | |
| 0560 | JUMPDEST | |
| 0561 | PUSH2 | 0x0569 |
| 0564 | DUP3 | |
| 0565 | PUSH2 | 0x206e |
| 0568 | JUMP | |
| 0569 | JUMPDEST | |
| 056a | PUSH2 | 0x0550 |
| 056d | JUMP | |
| 056e | JUMPDEST | |
| 056f | SWAP1 | |
| 0570 | PUSH2 | 0x057a |
| 0573 | DUP4 | |
| 0574 | DUP6 | |
| 0575 | DUP9 | |
| 0576 | PUSH2 | 0x1eb5 |
| 0579 | JUMP | |
| 057a | JUMPDEST | |
| 057b | CALLDATALOAD | |
| 057c | ISZERO | |
| 057d | PUSH2 | 0x05c2 |
| 0580 | JUMPI | |
| 0581 | PUSH2 | 0x05bc |
| 0584 | SWAP1 | |
| 0585 | PUSH2 | 0x0598 |
| 0588 | PUSH2 | 0x0590 |
| 058b | DUP6 | |
| 058c | PUSH2 | 0x212a |
| 058f | JUMP | |
| 0590 | JUMPDEST | |
| 0591 | SWAP5 | |
| 0592 | DUP7 | |
| 0593 | DUP10 | |
| 0594 | PUSH2 | 0x1eb5 |
| 0597 | JUMP | |
| 0598 | JUMPDEST | |
| 0599 | CALLDATALOAD | |
| 059a | DUP4 | |
| 059b | PUSH0 | |
| 059c | MSTORE | |
| 059d | PUSH1 | 0x03 |
| 059f | PUSH1 | 0x20 |
| 05a1 | MSTORE | |
| 05a2 | PUSH1 | 0x40 |
| 05a4 | PUSH0 | |
| 05a5 | KECCAK256 | |
| 05a6 | DUP3 | |
| 05a7 | DUP6 | |
| 05a8 | SHR | |
| 05a9 | PUSH0 | |
| 05aa | MSTORE | |
| 05ab | PUSH1 | 0x20 |
| 05ad | MSTORE | |
| 05ae | PUSH1 | 0x40 |
| 05b0 | PUSH0 | |
| 05b1 | KECCAK256 | |
| 05b2 | SSTORE | |
| 05b3 | PUSH1 | 0x01 |
| 05b5 | DUP4 | |
| 05b6 | SHL | |
| 05b7 | SWAP1 | |
| 05b8 | PUSH2 | 0x1bd4 |
| 05bb | JUMP | |
| 05bc | JUMPDEST | |
| 05bd | SWAP1 | |
| 05be | PUSH2 | 0x04f5 |
| 05c1 | JUMP | |
| 05c2 | JUMPDEST | |
| 05c3 | PUSH4 | 0x4425ca13 |
| 05c8 | PUSH1 | 0xe0 |
| 05ca | SHL | |
| 05cb | PUSH0 | |
| 05cc | MSTORE | |
| 05cd | PUSH1 | 0x04 |
| 05cf | PUSH0 | |
| 05d0 | REVERT | |
| 05d1 | JUMPDEST | |
| 05d2 | PUSH4 | 0xecc9b8ed |
| 05d7 | PUSH1 | 0xe0 |
| 05d9 | SHL | |
| 05da | PUSH0 | |
| 05db | MSTORE | |
| 05dc | PUSH1 | 0x04 |
| 05de | MSTORE | |
| 05df | PUSH1 | 0x24 |
| 05e1 | MSTORE | |
| 05e2 | PUSH1 | 0x44 |
| 05e4 | PUSH0 | |
| 05e5 | REVERT | |
| 05e6 | JUMPDEST | |
| 05e7 | PUSH1 | 0x01 |
| 05e9 | DUP1 | |
| 05ea | DUP3 | |
| 05eb | AND | |
| 05ec | EQ | |
| 05ed | PUSH2 | 0x05fa |
| 05f0 | JUMPI | |
| 05f1 | JUMPDEST | |
| 05f2 | PUSH1 | 0x01 |
| 05f4 | SHR | |
| 05f5 | DUP1 | |
| 05f6 | PUSH2 | 0x04d6 |
| 05f9 | JUMP | |
| 05fa | JUMPDEST | |
| 05fb | SWAP1 | |
| 05fc | PUSH2 | 0x0604 |
| 05ff | SWAP1 | |
| 0600 | PUSH2 | 0x212a |
| 0603 | JUMP | |
| 0604 | JUMPDEST | |
| 0605 | SWAP1 | |
| 0606 | PUSH2 | 0x05f1 |
| 0609 | JUMP | |
| 060a | JUMPDEST | |
| 060b | PUSH4 | 0xdc63d81f |
| 0610 | PUSH1 | 0xe0 |
| 0612 | SHL | |
| 0613 | PUSH0 | |
| 0614 | MSTORE | |
| 0615 | PUSH1 | 0x04 |
| 0617 | PUSH0 | |
| 0618 | REVERT | |
| 0619 | JUMPDEST | |
| 061a | PUSH1 | 0x40 |
| 061c | MLOAD | |
| 061d | PUSH1 | 0x20 |
| 061f | DUP2 | |
| 0620 | ADD | |
| 0621 | SWAP1 | |
| 0622 | PUSH1 | 0x40 |
| 0624 | DUP3 | |
| 0625 | MSTORE | |
| 0626 | PUSH2 | 0x064b |
| 0629 | DUP2 | |
| 062a | PUSH2 | 0x0637 |
| 062d | PUSH1 | 0x60 |
| 062f | DUP3 | |
| 0630 | ADD | |
| 0631 | DUP11 | |
| 0632 | DUP14 | |
| 0633 | PUSH2 | 0x1e73 |
| 0636 | JUMP | |
| 0637 | JUMPDEST | |
| 0638 | DUP11 | |
| 0639 | PUSH1 | 0x40 |
| 063b | DUP4 | |
| 063c | ADD | |
| 063d | MSTORE | |
| 063e | SUB | |
| 063f | PUSH1 | 0x1f |
| 0641 | NOT | |
| 0642 | DUP2 | |
| 0643 | ADD | |
| 0644 | DUP4 | |
| 0645 | MSTORE | |
| 0646 | DUP3 | |
| 0647 | PUSH2 | 0x1be1 |
| 064a | JUMP | |
| 064b | JUMPDEST | |
| 064c | MLOAD | |
| 064d | SWAP1 | |
| 064e | KECCAK256 | |
| 064f | DUP4 | |
| 0650 | EXTCODESIZE | |
| 0651 | ISZERO | |
| 0652 | PUSH2 | 0x02ec |
| 0655 | JUMPI | |
| 0656 | SWAP1 | |
| 0657 | DUP3 | |
| 0658 | PUSH1 | 0x01 |
| 065a | PUSH1 | 0x01 |
| 065c | PUSH1 | 0x40 |
| 065e | SHL | |
| 065f | SUB | |
| 0660 | SWAP6 | |
| 0661 | SWAP4 | |
| 0662 | SWAP3 | |
| 0663 | PUSH1 | 0x40 |
| 0665 | MLOAD | |
| 0666 | SWAP7 | |
| 0667 | DUP8 | |
| 0668 | SWAP6 | |
| 0669 | PUSH4 | 0x22f3f447 |
| 066e | PUSH1 | 0xe1 |
| 0670 | SHL | |
| 0671 | DUP8 | |
| 0672 | MSTORE | |
| 0673 | PUSH1 | 0x84 |
| 0675 | DUP8 | |
| 0676 | ADD | |
| 0677 | SWAP3 | |
| 0678 | PUSH32 | 0x405bbda3343b6e69c32fb7eafff8f0a1e55a5ee2ec35458b3abc776b26681952 |
| 0699 | PUSH1 | 0x04 |
| 069b | DUP10 | |
| 069c | ADD | |
| 069d | MSTORE | |
| 069e | PUSH1 | 0x24 |
| 06a0 | DUP9 | |
| 06a1 | ADD | |
| 06a2 | MSTORE | |
| 06a3 | AND | |
| 06a4 | PUSH1 | 0x44 |
| 06a6 | DUP7 | |
| 06a7 | ADD | |
| 06a8 | MSTORE | |
| 06a9 | PUSH1 | 0x80 |
| 06ab | PUSH1 | 0x64 |
| 06ad | DUP7 | |
| 06ae | ADD | |
| 06af | MSTORE | |
| 06b0 | MSTORE | |
| 06b1 | PUSH1 | 0xa4 |
| 06b3 | DUP4 | |
| 06b4 | ADD | |
| 06b5 | PUSH1 | 0xa0 |
| 06b7 | PUSH1 | 0x04 |
| 06b9 | DUP5 | |
| 06ba | PUSH1 | 0x05 |
| 06bc | SHL | |
| 06bd | DUP7 | |
| 06be | ADD | |
| 06bf | ADD | |
| 06c0 | ADD | |
| 06c1 | SWAP3 | |
| 06c2 | DUP3 | |
| 06c3 | PUSH0 | |
| 06c4 | SWAP1 | |
| 06c5 | PUSH1 | 0x7e |
| 06c7 | NOT | |
| 06c8 | DUP2 | |
| 06c9 | CALLDATASIZE | |
| 06ca | SUB | |
| 06cb | ADD | |
| 06cc | JUMPDEST | |
| 06cd | DUP4 | |
| 06ce | DUP4 | |
| 06cf | LT | |
| 06d0 | PUSH2 | 0x0713 |
| 06d3 | JUMPI | |
| 06d4 | POP | |
| 06d5 | POP | |
| 06d6 | POP | |
| 06d7 | POP | |
| 06d8 | POP | |
| 06d9 | POP | |
| 06da | SWAP2 | |
| 06db | DUP2 | |
| 06dc | PUSH0 | |
| 06dd | DUP2 | |
| 06de | DUP6 | |
| 06df | DUP3 | |
| 06e0 | SWAP7 | |
| 06e1 | POP | |
| 06e2 | SUB | |
| 06e3 | SWAP3 | |
| 06e4 | GAS | |
| 06e5 | CALL | |
| 06e6 | DUP1 | |
| 06e7 | ISZERO | |
| 06e8 | PUSH2 | 0x0708 |
| 06eb | JUMPI | |
| 06ec | PUSH2 | 0x06f8 |
| 06ef | JUMPI | |
| 06f0 | JUMPDEST | |
| 06f1 | DUP1 | |
| 06f2 | DUP1 | |
| 06f3 | DUP1 | |
| 06f4 | PUSH2 | 0x04c7 |
| 06f7 | JUMP | |
| 06f8 | JUMPDEST | |
| 06f9 | PUSH0 | |
| 06fa | PUSH2 | 0x0702 |
| 06fd | SWAP2 | |
| 06fe | PUSH2 | 0x1be1 |
| 0701 | JUMP | |
| 0702 | JUMPDEST | |
| 0703 | DUP4 | |
| 0704 | PUSH2 | 0x06f0 |
| 0707 | JUMP | |
| 0708 | JUMPDEST | |
| 0709 | PUSH1 | 0x40 |
| 070b | MLOAD | |
| 070c | RETURNDATASIZE | |
| 070d | PUSH0 | |
| 070e | DUP3 | |
| 070f | RETURNDATACOPY | |
| 0710 | RETURNDATASIZE | |
| 0711 | SWAP1 | |
| 0712 | REVERT | |
| 0713 | JUMPDEST | |
| 0714 | PUSH1 | 0xa3 |
| 0716 | NOT | |
| 0717 | DUP11 | |
| 0718 | DUP9 | |
| 0719 | SUB | |
| 071a | ADD | |
| 071b | DUP6 | |
| 071c | MSTORE | |
| 071d | SWAP5 | |
| 071e | SWAP7 | |
| 071f | POP | |
| 0720 | SWAP3 | |
| 0721 | SWAP5 | |
| 0722 | SWAP2 | |
| 0723 | SWAP4 | |
| 0724 | SWAP1 | |
| 0725 | SWAP3 | |
| 0726 | SWAP2 | |
| 0727 | DUP7 | |
| 0728 | CALLDATALOAD | |
| 0729 | DUP3 | |
| 072a | DUP2 | |
| 072b | SLT | |
| 072c | ISZERO | |
| 072d | PUSH2 | 0x02ec |
| 0730 | JUMPI | |
| 0731 | DUP4 | |
| 0732 | ADD | |
| 0733 | PUSH1 | 0x01 |
| 0735 | PUSH1 | 0x01 |
| 0737 | PUSH1 | 0xa0 |
| 0739 | SHL | |
| 073a | SUB | |
| 073b | PUSH2 | 0x0743 |
| 073e | DUP3 | |
| 073f | PUSH2 | 0x1a77 |
| 0742 | JUMP | |
| 0743 | JUMPDEST | |
| 0744 | AND | |
| 0745 | DUP3 | |
| 0746 | MSTORE | |
| 0747 | PUSH1 | 0x20 |
| 0749 | DUP2 | |
| 074a | ADD | |
| 074b | CALLDATALOAD | |
| 074c | SWAP2 | |
| 074d | PUSH1 | 0xff |
| 074f | DUP4 | |
| 0750 | AND | |
| 0751 | DUP1 | |
| 0752 | SWAP4 | |
| 0753 | SUB | |
| 0754 | PUSH2 | 0x02ec |
| 0757 | JUMPI | |
| 0758 | PUSH2 | 0x07a3 |
| 075b | PUSH1 | 0x20 |
| 075d | SWAP3 | |
| 075e | DUP3 | |
| 075f | PUSH1 | 0x01 |
| 0761 | SWAP6 | |
| 0762 | DUP6 | |
| 0763 | DUP1 | |
| 0764 | SWAP6 | |
| 0765 | ADD | |
| 0766 | MSTORE | |
| 0767 | PUSH2 | 0x0795 |
| 076a | PUSH2 | 0x078a |
| 076d | PUSH2 | 0x0779 |
| 0770 | PUSH1 | 0x40 |
| 0772 | DUP6 | |
| 0773 | ADD | |
| 0774 | DUP6 | |
| 0775 | PUSH2 | 0x1f15 |
| 0778 | JUMP | |
| 0779 | JUMPDEST | |
| 077a | PUSH1 | 0x80 |
| 077c | PUSH1 | 0x40 |
| 077e | DUP7 | |
| 077f | ADD | |
| 0780 | MSTORE | |
| 0781 | PUSH1 | 0x80 |
| 0783 | DUP6 | |
| 0784 | ADD | |
| 0785 | SWAP2 | |
| 0786 | PUSH2 | 0x1f46 |
| 0789 | JUMP | |
| 078a | JUMPDEST | |
| 078b | SWAP3 | |
| 078c | PUSH1 | 0x60 |
| 078e | DUP2 | |
| 078f | ADD | |
| 0790 | SWAP1 | |
| 0791 | PUSH2 | 0x1f15 |
| 0794 | JUMP | |
| 0795 | JUMPDEST | |
| 0796 | SWAP2 | |
| 0797 | PUSH1 | 0x60 |
| 0799 | DUP2 | |
| 079a | DUP6 | |
| 079b | SUB | |
| 079c | SWAP2 | |
| 079d | ADD | |
| 079e | MSTORE | |
| 079f | PUSH2 | 0x1f46 |
| 07a2 | JUMP | |
| 07a3 | JUMPDEST | |
| 07a4 | SWAP9 | |
| 07a5 | ADD | |
| 07a6 | SWAP7 | |
| 07a7 | ADD | |
| 07a8 | SWAP4 | |
| 07a9 | ADD | |
| 07aa | SWAP1 | |
| 07ab | SWAP2 | |
| 07ac | DUP9 | |
| 07ad | SWAP7 | |
| 07ae | SWAP6 | |
| 07af | SWAP5 | |
| 07b0 | SWAP3 | |
| 07b1 | PUSH2 | 0x06cc |
| 07b4 | JUMP | |
| 07b5 | JUMPDEST | |
| 07b6 | POP | |
| 07b7 | PUSH1 | 0x40 |
| 07b9 | MLOAD | |
| 07ba | PUSH4 | 0xf5778b03 |
| 07bf | PUSH1 | 0xe0 |
| 07c1 | SHL | |
| 07c2 | DUP2 | |
| 07c3 | MSTORE | |
| 07c4 | PUSH1 | 0x20 |
| 07c6 | DUP2 | |
| 07c7 | PUSH1 | 0x04 |
| 07c9 | DUP2 | |
| 07ca | DUP8 | |
| 07cb | GAS | |
| 07cc | STATICCALL | |
| 07cd | SWAP1 | |
| 07ce | DUP2 | |
| 07cf | ISZERO | |
| 07d0 | PUSH2 | 0x0708 |
| 07d3 | JUMPI | |
| 07d4 | PUSH0 | |
| 07d5 | SWAP2 | |
| 07d6 | PUSH2 | 0x07ec |
| 07d9 | JUMPI | |
| 07da | JUMPDEST | |
| 07db | POP | |
| 07dc | PUSH1 | 0x01 |
| 07de | PUSH1 | 0x01 |
| 07e0 | PUSH1 | 0xa0 |
| 07e2 | SHL | |
| 07e3 | SUB | |
| 07e4 | AND | |
| 07e5 | CALLER | |
| 07e6 | EQ | |
| 07e7 | ISZERO | |
| 07e8 | PUSH2 | 0x04c2 |
| 07eb | JUMP | |
| 07ec | JUMPDEST | |
| 07ed | PUSH2 | 0x080e |
| 07f0 | SWAP2 | |
| 07f1 | POP | |
| 07f2 | PUSH1 | 0x20 |
| 07f4 | RETURNDATASIZE | |
| 07f5 | PUSH1 | 0x20 |
| 07f7 | GT | |
| 07f8 | PUSH2 | 0x0814 |
| 07fb | JUMPI | |
| 07fc | JUMPDEST | |
| 07fd | PUSH2 | 0x0806 |
| 0800 | DUP2 | |
| 0801 | DUP4 | |
| 0802 | PUSH2 | 0x1be1 |
| 0805 | JUMP | |
| 0806 | JUMPDEST | |
| 0807 | DUP2 | |
| 0808 | ADD | |
| 0809 | SWAP1 | |
| 080a | PUSH2 | 0x1ef6 |
| 080d | JUMP | |
| 080e | JUMPDEST | |
| 080f | DUP9 | |
| 0810 | PUSH2 | 0x07da |
| 0813 | JUMP | |
| 0814 | JUMPDEST | |
| 0815 | POP | |
| 0816 | RETURNDATASIZE | |
| 0817 | PUSH2 | 0x07fc |
| 081a | JUMP | |
| 081b | JUMPDEST | |
| 081c | PUSH2 | 0x083d |
| 081f | SWAP2 | |
| 0820 | POP | |
| 0821 | PUSH1 | 0x20 |
| 0823 | RETURNDATASIZE | |
| 0824 | PUSH1 | 0x20 |
| 0826 | GT | |
| 0827 | PUSH2 | 0x0843 |
| 082a | JUMPI | |
| 082b | JUMPDEST | |
| 082c | PUSH2 | 0x0835 |
| 082f | DUP2 | |
| 0830 | DUP4 | |
| 0831 | PUSH2 | 0x1be1 |
| 0834 | JUMP | |
| 0835 | JUMPDEST | |
| 0836 | DUP2 | |
| 0837 | ADD | |
| 0838 | SWAP1 | |
| 0839 | PUSH2 | 0x1ede |
| 083c | JUMP | |
| 083d | JUMPDEST | |
| 083e | DUP9 | |
| 083f | PUSH2 | 0x04ba |
| 0842 | JUMP | |
| 0843 | JUMPDEST | |
| 0844 | POP | |
| 0845 | RETURNDATASIZE | |
| 0846 | PUSH2 | 0x082b |
| 0849 | JUMP | |
| 084a | JUMPDEST | |
| 084b | CALLVALUE | |
| 084c | PUSH2 | 0x02ec |
| 084f | JUMPI | |
| 0850 | PUSH0 | |
| 0851 | CALLDATASIZE | |
| 0852 | PUSH1 | 0x03 |
| 0854 | NOT | |
| 0855 | ADD | |
| 0856 | SLT | |
| 0857 | PUSH2 | 0x02ec |
| 085a | JUMPI | |
| 085b | PUSH1 | 0x20 |
| 085d | PUSH0 | |
| 085e | SLOAD | |
| 085f | PUSH1 | 0x40 |
| 0861 | MLOAD | |
| 0862 | SWAP1 | |
| 0863 | DUP2 | |
| 0864 | MSTORE | |
| 0865 | RETURN | |
| 0866 | JUMPDEST | |
| 0867 | CALLVALUE | |
| 0868 | PUSH2 | 0x02ec |
| 086b | JUMPI | |
| 086c | PUSH1 | 0x20 |
| 086e | CALLDATASIZE | |
| 086f | PUSH1 | 0x03 |
| 0871 | NOT | |
| 0872 | ADD | |
| 0873 | SLT | |
| 0874 | PUSH2 | 0x02ec |
| 0877 | JUMPI | |
| 0878 | PUSH1 | 0x20 |
| 087a | PUSH2 | 0x0884 |
| 087d | PUSH1 | 0x04 |
| 087f | CALLDATALOAD | |
| 0880 | PUSH2 | 0x206e |
| 0883 | JUMP | |
| 0884 | JUMPDEST | |
| 0885 | PUSH1 | 0x40 |
| 0887 | MLOAD | |
| 0888 | SWAP1 | |
| 0889 | DUP2 | |
| 088a | MSTORE | |
| 088b | RETURN | |
| 088c | JUMPDEST | |
| 088d | CALLVALUE | |
| 088e | PUSH2 | 0x02ec |
| 0891 | JUMPI | |
| 0892 | PUSH0 | |
| 0893 | CALLDATASIZE | |
| 0894 | PUSH1 | 0x03 |
| 0896 | NOT | |
| 0897 | ADD | |
| 0898 | SLT | |
| 0899 | PUSH2 | 0x02ec |
| 089c | JUMPI | |
| 089d | PUSH1 | 0x40 |
| 089f | MLOAD | |
| 08a0 | PUSH32 | 0x000000000000000000000000c0876d136341091581a489ce7f746692dddf498f |
| 08c1 | PUSH1 | 0x01 |
| 08c3 | PUSH1 | 0x01 |
| 08c5 | PUSH1 | 0xa0 |
| 08c7 | SHL | |
| 08c8 | SUB | |
| 08c9 | AND | |
| 08ca | DUP2 | |
| 08cb | MSTORE | |
| 08cc | PUSH1 | 0x20 |
| 08ce | SWAP1 | |
| 08cf | RETURN | |
| 08d0 | JUMPDEST | |
| 08d1 | CALLVALUE | |
| 08d2 | PUSH2 | 0x02ec |
| 08d5 | JUMPI | |
| 08d6 | PUSH1 | 0xa0 |
| 08d8 | CALLDATASIZE | |
| 08d9 | PUSH1 | 0x03 |
| 08db | NOT | |
| 08dc | ADD | |
| 08dd | SLT | |
| 08de | PUSH2 | 0x02ec |
| 08e1 | JUMPI | |
| 08e2 | PUSH2 | 0x08e9 |
| 08e5 | PUSH2 | 0x1a4b |
| 08e8 | JUMP | |
| 08e9 | JUMPDEST | |
| 08ea | POP | |
| 08eb | PUSH2 | 0x08f2 |
| 08ee | PUSH2 | 0x1a61 |
| 08f1 | JUMP | |
| 08f2 | JUMPDEST | |
| 08f3 | POP | |
| 08f4 | PUSH1 | 0x44 |
| 08f6 | CALLDATALOAD | |
| 08f7 | PUSH1 | 0x01 |
| 08f9 | PUSH1 | 0x01 |
| 08fb | PUSH1 | 0x40 |
| 08fd | SHL | |
| 08fe | SUB | |
| 08ff | DUP2 | |
| 0900 | GT | |
| 0901 | PUSH2 | 0x02ec |
| 0904 | JUMPI | |
| 0905 | PUSH2 | 0x0912 |
| 0908 | SWAP1 | |
| 0909 | CALLDATASIZE | |
| 090a | SWAP1 | |
| 090b | PUSH1 | 0x04 |
| 090d | ADD | |
| 090e | PUSH2 | 0x1b01 |
| 0911 | JUMP | |
| 0912 | JUMPDEST | |
| 0913 | POP | |
| 0914 | POP | |
| 0915 | PUSH1 | 0x64 |
| 0917 | CALLDATALOAD | |
| 0918 | PUSH1 | 0x01 |
| 091a | PUSH1 | 0x01 |
| 091c | PUSH1 | 0x40 |
| 091e | SHL | |
| 091f | SUB | |
| 0920 | DUP2 | |
| 0921 | GT | |
| 0922 | PUSH2 | 0x02ec |
| 0925 | JUMPI | |
| 0926 | PUSH2 | 0x0933 |
| 0929 | SWAP1 | |
| 092a | CALLDATASIZE | |
| 092b | SWAP1 | |
| 092c | PUSH1 | 0x04 |
| 092e | ADD | |
| 092f | PUSH2 | 0x1b01 |
| 0932 | JUMP | |
| 0933 | JUMPDEST | |
| 0934 | POP | |
| 0935 | POP | |
| 0936 | PUSH1 | 0x84 |
| 0938 | CALLDATALOAD | |
| 0939 | PUSH1 | 0x01 |
| 093b | PUSH1 | 0x01 |
| 093d | PUSH1 | 0x40 |
| 093f | SHL | |
| 0940 | SUB | |
| 0941 | DUP2 | |
| 0942 | GT | |
| 0943 | PUSH2 | 0x02ec |
| 0946 | JUMPI | |
| 0947 | PUSH2 | 0x0954 |
| 094a | SWAP1 | |
| 094b | CALLDATASIZE | |
| 094c | SWAP1 | |
| 094d | PUSH1 | 0x04 |
| 094f | ADD | |
| 0950 | PUSH2 | 0x1a8b |
| 0953 | JUMP | |
| 0954 | JUMPDEST | |
| 0955 | POP | |
| 0956 | POP | |
| 0957 | PUSH1 | 0x40 |
| 0959 | MLOAD | |
| 095a | PUSH4 | 0xbc197c81 |
| 095f | PUSH1 | 0xe0 |
| 0961 | SHL | |
| 0962 | DUP2 | |
| 0963 | MSTORE | |
| 0964 | PUSH1 | 0x20 |
| 0966 | SWAP1 | |
| 0967 | RETURN | |
| 0968 | JUMPDEST | |
| 0969 | CALLVALUE | |
| 096a | PUSH2 | 0x02ec |
| 096d | JUMPI | |
| 096e | PUSH0 | |
| 096f | CALLDATASIZE | |
| 0970 | PUSH1 | 0x03 |
| 0972 | NOT | |
| 0973 | ADD | |
| 0974 | SLT | |
| 0975 | PUSH2 | 0x02ec |
| 0978 | JUMPI | |
| 0979 | PUSH1 | 0x20 |
| 097b | PUSH1 | 0x40 |
| 097d | MLOAD | |
| 097e | PUSH32 | 0x27c91cbb7cc32319dd47788e8b096cc02ee8ccca641645266d7046769a12fbc3 |
| 099f | DUP2 | |
| 09a0 | MSTORE | |
| 09a1 | RETURN | |
| 09a2 | JUMPDEST | |
| 09a3 | CALLVALUE | |
| 09a4 | PUSH2 | 0x02ec |
| 09a7 | JUMPI | |
| 09a8 | PUSH0 | |
| 09a9 | CALLDATASIZE | |
| 09aa | PUSH1 | 0x03 |
| 09ac | NOT | |
| 09ad | ADD | |
| 09ae | SLT | |
| 09af | PUSH2 | 0x02ec |
| 09b2 | JUMPI | |
| 09b3 | PUSH1 | 0x20 |
| 09b5 | PUSH1 | 0x01 |
| 09b7 | PUSH1 | 0x01 |
| 09b9 | PUSH1 | 0x40 |
| 09bb | SHL | |
| 09bc | SUB | |
| 09bd | PUSH1 | 0x02 |
| 09bf | SLOAD | |
| 09c0 | AND | |
| 09c1 | PUSH1 | 0x40 |
| 09c3 | MLOAD | |
| 09c4 | SWAP1 | |
| 09c5 | DUP2 | |
| 09c6 | MSTORE | |
| 09c7 | RETURN | |
| 09c8 | JUMPDEST | |
| 09c9 | CALLVALUE | |
| 09ca | PUSH2 | 0x02ec |
| 09cd | JUMPI | |
| 09ce | PUSH1 | 0xa0 |
| 09d0 | CALLDATASIZE | |
| 09d1 | PUSH1 | 0x03 |
| 09d3 | NOT | |
| 09d4 | ADD | |
| 09d5 | SLT | |
| 09d6 | PUSH2 | 0x02ec |
| 09d9 | JUMPI | |
| 09da | PUSH1 | 0x04 |
| 09dc | CALLDATALOAD | |
| 09dd | PUSH1 | 0x04 |
| 09df | DUP2 | |
| 09e0 | LT | |
| 09e1 | ISZERO | |
| 09e2 | PUSH2 | 0x02ec |
| 09e5 | JUMPI | |
| 09e6 | PUSH2 | 0x09ed |
| 09e9 | PUSH2 | 0x1a61 |
| 09ec | JUMP | |
| 09ed | JUMPDEST | |
| 09ee | SWAP1 | |
| 09ef | PUSH1 | 0x64 |
| 09f1 | CALLDATALOAD | |
| 09f2 | SWAP1 | |
| 09f3 | PUSH1 | 0x84 |
| 09f5 | CALLDATALOAD | |
| 09f6 | PUSH1 | 0x01 |
| 09f8 | PUSH1 | 0x01 |
| 09fa | PUSH1 | 0xa0 |
| 09fc | SHL | |
| 09fd | SUB | |
| 09fe | DUP2 | |
| 09ff | AND | |
| 0a00 | SWAP2 | |
| 0a01 | PUSH1 | 0x44 |
| 0a03 | CALLDATALOAD | |
| 0a04 | SWAP2 | |
| 0a05 | DUP4 | |
| 0a06 | DUP2 | |
| 0a07 | SUB | |
| 0a08 | PUSH2 | 0x02ec |
| 0a0b | JUMPI | |
| 0a0c | PUSH2 | 0x0a13 |
| 0a0f | PUSH2 | 0x26e4 |
| 0a12 | JUMP | |
| 0a13 | JUMPDEST | |
| 0a14 | PUSH1 | 0x40 |
| 0a16 | MLOAD | |
| 0a17 | PUSH4 | 0xf5778b03 |
| 0a1c | PUSH1 | 0xe0 |
| 0a1e | SHL | |
| 0a1f | DUP2 | |
| 0a20 | MSTORE | |
| 0a21 | PUSH1 | 0x20 |
| 0a23 | DUP2 | |
| 0a24 | PUSH1 | 0x04 |
| 0a26 | DUP2 | |
| 0a27 | PUSH32 | 0x00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf |
| 0a48 | PUSH1 | 0x01 |
| 0a4a | PUSH1 | 0x01 |
| 0a4c | PUSH1 | 0xa0 |
| 0a4e | SHL | |
| 0a4f | SUB | |
| 0a50 | AND | |
| 0a51 | GAS | |
| 0a52 | STATICCALL | |
| 0a53 | SWAP1 | |
| 0a54 | DUP2 | |
| 0a55 | ISZERO | |
| 0a56 | PUSH2 | 0x0708 |
| 0a59 | JUMPI | |
| 0a5a | PUSH0 | |
| 0a5b | SWAP2 | |
| 0a5c | PUSH2 | 0x0c7c |
| 0a5f | JUMPI | |
| 0a60 | JUMPDEST | |
| 0a61 | POP | |
| 0a62 | DUP5 | |
| 0a63 | ISZERO | |
| 0a64 | SWAP1 | |
| 0a65 | DUP2 | |
| 0a66 | ISZERO | |
| 0a67 | PUSH2 | 0x0c58 |
| 0a6a | JUMPI | |
| 0a6b | JUMPDEST | |
| 0a6c | POP | |
| 0a6d | PUSH2 | 0x0c45 |
| 0a70 | JUMPI | |
| 0a71 | PUSH2 | 0x0a7b |
| 0a74 | DUP4 | |
| 0a75 | DUP8 | |
| 0a76 | DUP5 | |
| 0a77 | PUSH2 | 0x1ec5 |
| 0a7a | JUMP | |
| 0a7b | JUMPDEST | |
| 0a7c | SWAP5 | |
| 0a7d | PUSH0 | |
| 0a7e | NOT | |
| 0a7f | DUP2 | |
| 0a80 | SUB | |
| 0a81 | PUSH2 | 0x0c40 |
| 0a84 | JUMPI | |
| 0a85 | POP | |
| 0a86 | DUP5 | |
| 0a87 | JUMPDEST | |
| 0a88 | DUP1 | |
| 0a89 | SWAP6 | |
| 0a8a | DUP2 | |
| 0a8b | ISZERO | |
| 0a8c | PUSH2 | 0x0c31 |
| 0a8f | JUMPI | |
| 0a90 | DUP1 | |
| 0a91 | DUP3 | |
| 0a92 | GT | |
| 0a93 | PUSH2 | 0x0c0a |
| 0a96 | JUMPI | |
| 0a97 | POP | |
| 0a98 | PUSH0 | |
| 0a99 | SWAP2 | |
| 0a9a | DUP4 | |
| 0a9b | PUSH2 | 0x0b28 |
| 0a9e | JUMPI | |
| 0a9f | POP | |
| 0aa0 | POP | |
| 0aa1 | PUSH0 | |
| 0aa2 | DUP1 | |
| 0aa3 | DUP1 | |
| 0aa4 | DUP1 | |
| 0aa5 | DUP9 | |
| 0aa6 | DUP9 | |
| 0aa7 | GAS | |
| 0aa8 | CALL | |
| 0aa9 | PUSH2 | 0x0ab0 |
| 0aac | PUSH2 | 0x203f |
| 0aaf | JUMP | |
| 0ab0 | JUMPDEST | |
| 0ab1 | POP | |
| 0ab2 | ISZERO | |
| 0ab3 | PUSH2 | 0x0b15 |
| 0ab6 | JUMPI | |
| 0ab7 | JUMPDEST | |
| 0ab8 | PUSH2 | 0x0b01 |
| 0abb | JUMPI | |
| 0abc | PUSH1 | 0x40 |
| 0abe | DUP1 | |
| 0abf | MLOAD | |
| 0ac0 | SWAP3 | |
| 0ac1 | DUP4 | |
| 0ac2 | MSTORE | |
| 0ac3 | PUSH1 | 0x20 |
| 0ac5 | DUP4 | |
| 0ac6 | DUP2 | |
| 0ac7 | ADD | |
| 0ac8 | DUP7 | |
| 0ac9 | SWAP1 | |
| 0aca | MSTORE | |
| 0acb | SWAP6 | |
| 0acc | PUSH1 | 0x01 |
| 0ace | PUSH1 | 0x01 |
| 0ad0 | PUSH1 | 0xa0 |
| 0ad2 | SHL | |
| 0ad3 | SUB | |
| 0ad4 | AND | |
| 0ad5 | SWAP3 | |
| 0ad6 | PUSH32 | 0x7643c83e539cea2f6bf506545392e52cfd5f917e327efbcd0ba28f29c28d042e |
| 0af7 | SWAP2 | |
| 0af8 | SWAP1 | |
| 0af9 | LOG4 | |
| 0afa | PUSH1 | 0x40 |
| 0afc | MLOAD | |
| 0afd | SWAP1 | |
| 0afe | DUP2 | |
| 0aff | MSTORE | |
| 0b00 | RETURN | |
| 0b01 | JUMPDEST | |
| 0b02 | PUSH4 | 0x4e487b71 |
| 0b07 | PUSH1 | 0xe0 |
| 0b09 | SHL | |
| 0b0a | PUSH0 | |
| 0b0b | MSTORE | |
| 0b0c | PUSH1 | 0x21 |
| 0b0e | PUSH1 | 0x04 |
| 0b10 | MSTORE | |
| 0b11 | PUSH1 | 0x24 |
| 0b13 | PUSH0 | |
| 0b14 | REVERT | |
| 0b15 | JUMPDEST | |
| 0b16 | PUSH4 | 0x65f4a9ef |
| 0b1b | PUSH1 | 0xe1 |
| 0b1d | SHL | |
| 0b1e | PUSH0 | |
| 0b1f | MSTORE | |
| 0b20 | PUSH0 | |
| 0b21 | PUSH1 | 0x04 |
| 0b23 | MSTORE | |
| 0b24 | PUSH1 | 0x24 |
| 0b26 | PUSH0 | |
| 0b27 | REVERT | |
| 0b28 | JUMPDEST | |
| 0b29 | PUSH0 | |
| 0b2a | SWAP3 | |
| 0b2b | POP | |
| 0b2c | SWAP1 | |
| 0b2d | PUSH1 | 0x01 |
| 0b2f | DUP5 | |
| 0b30 | SUB | |
| 0b31 | PUSH2 | 0x0b78 |
| 0b34 | JUMPI | |
| 0b35 | POP | |
| 0b36 | PUSH1 | 0x40 |
| 0b38 | MLOAD | |
| 0b39 | PUSH4 | 0xa9059cbb |
| 0b3e | PUSH1 | 0xe0 |
| 0b40 | SHL | |
| 0b41 | PUSH1 | 0x20 |
| 0b43 | DUP3 | |
| 0b44 | ADD | |
| 0b45 | MSTORE | |
| 0b46 | PUSH1 | 0x01 |
| 0b48 | PUSH1 | 0x01 |
| 0b4a | PUSH1 | 0xa0 |
| 0b4c | SHL | |
| 0b4d | SUB | |
| 0b4e | SWAP1 | |
| 0b4f | SWAP2 | |
| 0b50 | AND | |
| 0b51 | PUSH1 | 0x24 |
| 0b53 | DUP3 | |
| 0b54 | ADD | |
| 0b55 | MSTORE | |
| 0b56 | PUSH1 | 0x44 |
| 0b58 | DUP2 | |
| 0b59 | ADD | |
| 0b5a | DUP7 | |
| 0b5b | SWAP1 | |
| 0b5c | MSTORE | |
| 0b5d | PUSH2 | 0x0b73 |
| 0b60 | SWAP1 | |
| 0b61 | PUSH2 | 0x0b6d |
| 0b64 | DUP2 | |
| 0b65 | PUSH1 | 0x64 |
| 0b67 | DUP2 | |
| 0b68 | ADD | |
| 0b69 | PUSH2 | 0x01d0 |
| 0b6c | JUMP | |
| 0b6d | JUMPDEST | |
| 0b6e | DUP8 | |
| 0b6f | PUSH2 | 0x2882 |
| 0b72 | JUMP | |
| 0b73 | JUMPDEST | |
| 0b74 | PUSH2 | 0x0ab7 |
| 0b77 | JUMP | |
| 0b78 | JUMPDEST | |
| 0b79 | PUSH0 | |
| 0b7a | SWAP7 | |
| 0b7b | SWAP3 | |
| 0b7c | POP | |
| 0b7d | SWAP1 | |
| 0b7e | POP | |
| 0b7f | PUSH1 | 0x02 |
| 0b81 | DUP4 | |
| 0b82 | SUB | |
| 0b83 | PUSH2 | 0x0bbf |
| 0b86 | JUMPI | |
| 0b87 | POP | |
| 0b88 | POP | |
| 0b89 | PUSH1 | 0x01 |
| 0b8b | SWAP4 | |
| 0b8c | PUSH2 | 0x0b73 |
| 0b8f | PUSH1 | 0x40 |
| 0b91 | MLOAD | |
| 0b92 | PUSH4 | 0x23b872dd |
| 0b97 | PUSH1 | 0xe0 |
| 0b99 | SHL | |
| 0b9a | PUSH1 | 0x20 |
| 0b9c | DUP3 | |
| 0b9d | ADD | |
| 0b9e | MSTORE | |
| 0b9f | ADDRESS | |
| 0ba0 | PUSH1 | 0x24 |
| 0ba2 | DUP3 | |
| 0ba3 | ADD | |
| 0ba4 | MSTORE | |
| 0ba5 | DUP6 | |
| 0ba6 | PUSH1 | 0x44 |
| 0ba8 | DUP3 | |
| 0ba9 | ADD | |
| 0baa | MSTORE | |
| 0bab | DUP5 | |
| 0bac | PUSH1 | 0x64 |
| 0bae | DUP3 | |
| 0baf | ADD | |
| 0bb0 | MSTORE | |
| 0bb1 | PUSH1 | 0x64 |
| 0bb3 | DUP2 | |
| 0bb4 | MSTORE | |
| 0bb5 | PUSH2 | 0x0b6d |
| 0bb8 | PUSH1 | 0x84 |
| 0bba | DUP3 | |
| 0bbb | PUSH2 | 0x1be1 |
| 0bbe | JUMP | |
| 0bbf | JUMPDEST | |
| 0bc0 | PUSH2 | 0x0b73 |
| 0bc3 | SWAP1 | |
| 0bc4 | PUSH1 | 0x40 |
| 0bc6 | SWAP7 | |
| 0bc7 | SWAP3 | |
| 0bc8 | SWAP7 | |
| 0bc9 | MLOAD | |
| 0bca | SWAP1 | |
| 0bcb | PUSH4 | 0x79212195 |
| 0bd0 | PUSH1 | 0xe1 |
| 0bd2 | SHL | |
| 0bd3 | PUSH1 | 0x20 |
| 0bd5 | DUP4 | |
| 0bd6 | ADD | |
| 0bd7 | MSTORE | |
| 0bd8 | ADDRESS | |
| 0bd9 | PUSH1 | 0x24 |
| 0bdb | DUP4 | |
| 0bdc | ADD | |
| 0bdd | MSTORE | |
| 0bde | DUP7 | |
| 0bdf | PUSH1 | 0x44 |
| 0be1 | DUP4 | |
| 0be2 | ADD | |
| 0be3 | MSTORE | |
| 0be4 | DUP6 | |
| 0be5 | PUSH1 | 0x64 |
| 0be7 | DUP4 | |
| 0be8 | ADD | |
| 0be9 | MSTORE | |
| 0bea | PUSH1 | 0x84 |
| 0bec | DUP3 | |
| 0bed | ADD | |
| 0bee | MSTORE | |
| 0bef | PUSH1 | 0xa0 |
| 0bf1 | PUSH1 | 0xa4 |
| 0bf3 | DUP3 | |
| 0bf4 | ADD | |
| 0bf5 | MSTORE | |
| 0bf6 | PUSH0 | |
| 0bf7 | PUSH1 | 0xc4 |
| 0bf9 | DUP3 | |
| 0bfa | ADD | |
| 0bfb | MSTORE | |
| 0bfc | PUSH1 | 0xc4 |
| 0bfe | DUP2 | |
| 0bff | MSTORE | |
| 0c00 | PUSH2 | 0x0b6d |
| 0c03 | PUSH1 | 0xe4 |
| 0c05 | DUP3 | |
| 0c06 | PUSH2 | 0x1be1 |
| 0c09 | JUMP | |
| 0c0a | JUMPDEST | |
| 0c0b | PUSH4 | 0x21909681 |
| 0c10 | PUSH1 | 0xe0 |
| 0c12 | SHL | |
| 0c13 | PUSH0 | |
| 0c14 | SWAP1 | |
| 0c15 | DUP2 | |
| 0c16 | MSTORE | |
| 0c17 | PUSH1 | 0x01 |
| 0c19 | PUSH1 | 0x01 |
| 0c1b | PUSH1 | 0xa0 |
| 0c1d | SHL | |
| 0c1e | SUB | |
| 0c1f | DUP10 | |
| 0c20 | AND | |
| 0c21 | PUSH1 | 0x04 |
| 0c23 | MSTORE | |
| 0c24 | PUSH1 | 0x24 |
| 0c26 | SWAP3 | |
| 0c27 | SWAP1 | |
| 0c28 | SWAP3 | |
| 0c29 | MSTORE | |
| 0c2a | PUSH1 | 0x44 |
| 0c2c | MSTORE | |
| 0c2d | PUSH1 | 0x64 |
| 0c2f | SWAP1 | |
| 0c30 | REVERT | |
| 0c31 | JUMPDEST | |
| 0c32 | PUSH4 | 0x7c2e506f |
| 0c37 | PUSH1 | 0xe1 |
| 0c39 | SHL | |
| 0c3a | PUSH0 | |
| 0c3b | MSTORE | |
| 0c3c | PUSH1 | 0x04 |
| 0c3e | PUSH0 | |
| 0c3f | REVERT | |
| 0c40 | JUMPDEST | |
| 0c41 | PUSH2 | 0x0a87 |
| 0c44 | JUMP | |
| 0c45 | JUMPDEST | |
| 0c46 | DUP4 | |
| 0c47 | PUSH4 | 0x15150d4d |
| 0c4c | PUSH1 | 0xe3 |
| 0c4e | SHL | |
| 0c4f | PUSH0 | |
| 0c50 | MSTORE | |
| 0c51 | PUSH1 | 0x04 |
| 0c53 | MSTORE | |
| 0c54 | PUSH1 | 0x24 |
| 0c56 | PUSH0 | |
| 0c57 | REVERT | |
| 0c58 | JUMPDEST | |
| 0c59 | PUSH1 | 0x01 |
| 0c5b | PUSH1 | 0x01 |
| 0c5d | PUSH1 | 0xa0 |
| 0c5f | SHL | |
| 0c60 | SUB | |
| 0c61 | AND | |
| 0c62 | DUP6 | |
| 0c63 | EQ | |
| 0c64 | ISZERO | |
| 0c65 | SWAP1 | |
| 0c66 | POP | |
| 0c67 | DUP1 | |
| 0c68 | PUSH2 | 0x0c72 |
| 0c6b | JUMPI | |
| 0c6c | JUMPDEST | |
| 0c6d | DUP8 | |
| 0c6e | PUSH2 | 0x0a6b |
| 0c71 | JUMP | |
| 0c72 | JUMPDEST | |
| 0c73 | POP | |
| 0c74 | CALLER | |
| 0c75 | DUP5 | |
| 0c76 | EQ | |
| 0c77 | ISZERO | |
| 0c78 | PUSH2 | 0x0c6c |
| 0c7b | JUMP | |
| 0c7c | JUMPDEST | |
| 0c7d | PUSH2 | 0x0c95 |
| 0c80 | SWAP2 | |
| 0c81 | POP | |
| 0c82 | PUSH1 | 0x20 |
| 0c84 | RETURNDATASIZE | |
| 0c85 | PUSH1 | 0x20 |
| 0c87 | GT | |
| 0c88 | PUSH2 | 0x0814 |
| 0c8b | JUMPI | |
| 0c8c | PUSH2 | 0x0806 |
| 0c8f | DUP2 | |
| 0c90 | DUP4 | |
| 0c91 | PUSH2 | 0x1be1 |
| 0c94 | JUMP | |
| 0c95 | JUMPDEST | |
| 0c96 | DUP8 | |
| 0c97 | PUSH2 | 0x0a60 |
| 0c9a | JUMP | |
| 0c9b | JUMPDEST | |
| 0c9c | CALLVALUE | |
| 0c9d | PUSH2 | 0x02ec |
| 0ca0 | JUMPI | |
| 0ca1 | PUSH1 | 0x80 |
| 0ca3 | CALLDATASIZE | |
| 0ca4 | PUSH1 | 0x03 |
| 0ca6 | NOT | |
| 0ca7 | ADD | |
| 0ca8 | SLT | |
| 0ca9 | PUSH2 | 0x02ec |
| 0cac | JUMPI | |
| 0cad | PUSH1 | 0x24 |
| 0caf | CALLDATALOAD | |
| 0cb0 | PUSH1 | 0x04 |
| 0cb2 | CALLDATALOAD | |
| 0cb3 | PUSH2 | 0x0cba |
| 0cb6 | PUSH2 | 0x1b31 |
| 0cb9 | JUMP | |
| 0cba | JUMPDEST | |
| 0cbb | PUSH1 | 0x64 |
| 0cbd | CALLDATALOAD | |
| 0cbe | PUSH1 | 0x01 |
| 0cc0 | PUSH1 | 0x01 |
| 0cc2 | PUSH1 | 0x40 |
| 0cc4 | SHL | |
| 0cc5 | SUB | |
| 0cc6 | DUP2 | |
| 0cc7 | GT | |
| 0cc8 | PUSH2 | 0x02ec |
| 0ccb | JUMPI | |
| 0ccc | PUSH2 | 0x0cd9 |
| 0ccf | SWAP1 | |
| 0cd0 | CALLDATASIZE | |
| 0cd1 | SWAP1 | |
| 0cd2 | PUSH1 | 0x04 |
| 0cd4 | ADD | |
| 0cd5 | PUSH2 | 0x1b01 |
| 0cd8 | JUMP | |
| 0cd9 | JUMPDEST | |
| 0cda | PUSH1 | 0x40 |
| 0cdc | MLOAD | |
| 0cdd | PUSH4 | 0x28305db1 |
| 0ce2 | PUSH1 | 0xe2 |
| 0ce4 | SHL | |
| 0ce5 | DUP2 | |
| 0ce6 | MSTORE | |
| 0ce7 | PUSH32 | 0x00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf |
| 0d08 | PUSH1 | 0x01 |
| 0d0a | PUSH1 | 0x01 |
| 0d0c | PUSH1 | 0xa0 |
| 0d0e | SHL | |
| 0d0f | SUB | |
| 0d10 | AND | |
| 0d11 | SWAP4 | |
| 0d12 | SWAP3 | |
| 0d13 | SWAP1 | |
| 0d14 | PUSH1 | 0x20 |
| 0d16 | DUP2 | |
| 0d17 | PUSH1 | 0x04 |
| 0d19 | DUP2 | |
| 0d1a | DUP9 | |
| 0d1b | GAS | |
| 0d1c | STATICCALL | |
| 0d1d | SWAP1 | |
| 0d1e | DUP2 | |
| 0d1f | ISZERO | |
| 0d20 | PUSH2 | 0x0708 |
| 0d23 | JUMPI | |
| 0d24 | PUSH0 | |
| 0d25 | SWAP2 | |
| 0d26 | PUSH2 | 0x0f9d |
| 0d29 | JUMPI | |
| 0d2a | JUMPDEST | |
| 0d2b | POP | |
| 0d2c | DUP1 | |
| 0d2d | ISZERO | |
| 0d2e | PUSH2 | 0x0f47 |
| 0d31 | JUMPI | |
| 0d32 | JUMPDEST | |
| 0d33 | PUSH2 | 0x0df7 |
| 0d36 | JUMPI | |
| 0d37 | JUMPDEST | |
| 0d38 | POP | |
| 0d39 | POP | |
| 0d3a | POP | |
| 0d3b | DUP3 | |
| 0d3c | PUSH2 | 0x0d79 |
| 0d3f | JUMPI | |
| 0d40 | JUMPDEST | |
| 0d41 | PUSH32 | 0xbfc08a458e488f0e56f7ff4bfe317bed1ba5d3f7ef5a2bda241528695f6fcdf3 |
| 0d62 | PUSH1 | 0x40 |
| 0d64 | DUP4 | |
| 0d65 | DUP6 | |
| 0d66 | DUP2 | |
| 0d67 | PUSH0 | |
| 0d68 | SSTORE | |
| 0d69 | DUP1 | |
| 0d6a | PUSH1 | 0x01 |
| 0d6c | SSTORE | |
| 0d6d | DUP3 | |
| 0d6e | MLOAD | |
| 0d6f | SWAP2 | |
| 0d70 | DUP3 | |
| 0d71 | MSTORE | |
| 0d72 | PUSH1 | 0x20 |
| 0d74 | DUP3 | |
| 0d75 | ADD | |
| 0d76 | MSTORE | |
| 0d77 | LOG1 | |
| 0d78 | STOP | |
| 0d79 | JUMPDEST | |
| 0d7a | PUSH1 | 0x20 |
| 0d7c | PUSH1 | 0x24 |
| 0d7e | SWAP2 | |
| 0d7f | PUSH1 | 0x40 |
| 0d81 | MLOAD | |
| 0d82 | SWAP3 | |
| 0d83 | DUP4 | |
| 0d84 | DUP1 | |
| 0d85 | SWAP3 | |
| 0d86 | PUSH4 | 0x342f6163 |
| 0d8b | PUSH1 | 0xe0 |
| 0d8d | SHL | |
| 0d8e | DUP3 | |
| 0d8f | MSTORE | |
| 0d90 | DUP7 | |
| 0d91 | PUSH1 | 0x04 |
| 0d93 | DUP4 | |
| 0d94 | ADD | |
| 0d95 | MSTORE | |
| 0d96 | GAS | |
| 0d97 | STATICCALL | |
| 0d98 | SWAP1 | |
| 0d99 | DUP2 | |
| 0d9a | ISZERO | |
| 0d9b | PUSH2 | 0x0708 |
| 0d9e | JUMPI | |
| 0d9f | PUSH0 | |
| 0da0 | SWAP2 | |
| 0da1 | PUSH2 | 0x0dc5 |
| 0da4 | JUMPI | |
| 0da5 | JUMPDEST | |
| 0da6 | POP | |
| 0da7 | DUP3 | |
| 0da8 | DUP2 | |
| 0da9 | LT | |
| 0daa | ISZERO | |
| 0dab | PUSH2 | 0x0d40 |
| 0dae | JUMPI | |
| 0daf | SWAP1 | |
| 0db0 | POP | |
| 0db1 | PUSH4 | 0x3770da33 |
| 0db6 | PUSH1 | 0xe1 |
| 0db8 | SHL | |
| 0db9 | PUSH0 | |
| 0dba | MSTORE | |
| 0dbb | PUSH1 | 0x04 |
| 0dbd | MSTORE | |
| 0dbe | PUSH1 | 0x24 |
| 0dc0 | MSTORE | |
| 0dc1 | PUSH1 | 0x44 |
| 0dc3 | PUSH0 | |
| 0dc4 | REVERT | |
| 0dc5 | JUMPDEST | |
| 0dc6 | SWAP1 | |
| 0dc7 | POP | |
| 0dc8 | PUSH1 | 0x20 |
| 0dca | DUP2 | |
| 0dcb | RETURNDATASIZE | |
| 0dcc | PUSH1 | 0x20 |
| 0dce | GT | |
| 0dcf | PUSH2 | 0x0def |
| 0dd2 | JUMPI | |
| 0dd3 | JUMPDEST | |
| 0dd4 | DUP2 | |
| 0dd5 | PUSH2 | 0x0de0 |
| 0dd8 | PUSH1 | 0x20 |
| 0dda | SWAP4 | |
| 0ddb | DUP4 | |
| 0ddc | PUSH2 | 0x1be1 |
| 0ddf | JUMP | |
| 0de0 | JUMPDEST | |
| 0de1 | DUP2 | |
| 0de2 | ADD | |
| 0de3 | SUB | |
| 0de4 | SLT | |
| 0de5 | PUSH2 | 0x02ec |
| 0de8 | JUMPI | |
| 0de9 | MLOAD | |
| 0dea | DUP4 | |
| 0deb | PUSH2 | 0x0da5 |
| 0dee | JUMP | |
| 0def | JUMPDEST | |
| 0df0 | RETURNDATASIZE | |
| 0df1 | SWAP2 | |
| 0df2 | POP | |
| 0df3 | PUSH2 | 0x0dd3 |
| 0df6 | JUMP | |
| 0df7 | JUMPDEST | |
| 0df8 | PUSH1 | 0x40 |
| 0dfa | MLOAD | |
| 0dfb | PUSH1 | 0x20 |
| 0dfd | DUP2 | |
| 0dfe | ADD | |
| 0dff | SWAP1 | |
| 0e00 | DUP7 | |
| 0e01 | DUP3 | |
| 0e02 | MSTORE | |
| 0e03 | DUP8 | |
| 0e04 | PUSH1 | 0x40 |
| 0e06 | DUP3 | |
| 0e07 | ADD | |
| 0e08 | MSTORE | |
| 0e09 | PUSH1 | 0x40 |
| 0e0b | DUP2 | |
| 0e0c | MSTORE | |
| 0e0d | PUSH2 | 0x0e17 |
| 0e10 | PUSH1 | 0x60 |
| 0e12 | DUP3 | |
| 0e13 | PUSH2 | 0x1be1 |
| 0e16 | JUMP | |
| 0e17 | JUMPDEST | |
| 0e18 | MLOAD | |
| 0e19 | SWAP1 | |
| 0e1a | KECCAK256 | |
| 0e1b | DUP5 | |
| 0e1c | EXTCODESIZE | |
| 0e1d | ISZERO | |
| 0e1e | PUSH2 | 0x02ec |
| 0e21 | JUMPI | |
| 0e22 | SWAP1 | |
| 0e23 | DUP3 | |
| 0e24 | PUSH1 | 0x01 |
| 0e26 | PUSH1 | 0x01 |
| 0e28 | PUSH1 | 0x40 |
| 0e2a | SHL | |
| 0e2b | SUB | |
| 0e2c | SWAP5 | |
| 0e2d | SWAP3 | |
| 0e2e | PUSH1 | 0x40 |
| 0e30 | MLOAD | |
| 0e31 | SWAP6 | |
| 0e32 | DUP7 | |
| 0e33 | SWAP5 | |
| 0e34 | PUSH4 | 0x22f3f447 |
| 0e39 | PUSH1 | 0xe1 |
| 0e3b | SHL | |
| 0e3c | DUP7 | |
| 0e3d | MSTORE | |
| 0e3e | PUSH1 | 0x84 |
| 0e40 | DUP7 | |
| 0e41 | ADD | |
| 0e42 | SWAP3 | |
| 0e43 | PUSH32 | 0x27c91cbb7cc32319dd47788e8b096cc02ee8ccca641645266d7046769a12fbc3 |
| 0e64 | PUSH1 | 0x04 |
| 0e66 | DUP9 | |
| 0e67 | ADD | |
| 0e68 | MSTORE | |
| 0e69 | PUSH1 | 0x24 |
| 0e6b | DUP8 | |
| 0e6c | ADD | |
| 0e6d | MSTORE | |
| 0e6e | AND | |
| 0e6f | PUSH1 | 0x44 |
| 0e71 | DUP6 | |
| 0e72 | ADD | |
| 0e73 | MSTORE | |
| 0e74 | PUSH1 | 0x80 |
| 0e76 | PUSH1 | 0x64 |
| 0e78 | DUP6 | |
| 0e79 | ADD | |
| 0e7a | MSTORE | |
| 0e7b | MSTORE | |
| 0e7c | PUSH1 | 0xa4 |
| 0e7e | DUP3 | |
| 0e7f | ADD | |
| 0e80 | PUSH1 | 0xa0 |
| 0e82 | PUSH1 | 0x04 |
| 0e84 | DUP6 | |
| 0e85 | PUSH1 | 0x05 |
| 0e87 | SHL | |
| 0e88 | DUP6 | |
| 0e89 | ADD | |
| 0e8a | ADD | |
| 0e8b | ADD | |
| 0e8c | SWAP4 | |
| 0e8d | DUP3 | |
| 0e8e | PUSH0 | |
| 0e8f | SWAP1 | |
| 0e90 | PUSH1 | 0x7e |
| 0e92 | NOT | |
| 0e93 | DUP2 | |
| 0e94 | CALLDATASIZE | |
| 0e95 | SUB | |
| 0e96 | ADD | |
| 0e97 | JUMPDEST | |
| 0e98 | DUP4 | |
| 0e99 | DUP4 | |
| 0e9a | LT | |
| 0e9b | PUSH2 | 0x0ed1 |
| 0e9e | JUMPI | |
| 0e9f | POP | |
| 0ea0 | POP | |
| 0ea1 | POP | |
| 0ea2 | POP | |
| 0ea3 | POP | |
| 0ea4 | POP | |
| 0ea5 | DUP1 | |
| 0ea6 | DUP3 | |
| 0ea7 | PUSH0 | |
| 0ea8 | SWAP4 | |
| 0ea9 | POP | |
| 0eaa | SUB | |
| 0eab | DUP2 | |
| 0eac | DUP4 | |
| 0ead | DUP7 | |
| 0eae | GAS | |
| 0eaf | CALL | |
| 0eb0 | DUP1 | |
| 0eb1 | ISZERO | |
| 0eb2 | PUSH2 | 0x0708 |
| 0eb5 | JUMPI | |
| 0eb6 | PUSH2 | 0x0ec1 |
| 0eb9 | JUMPI | |
| 0eba | JUMPDEST | |
| 0ebb | DUP1 | |
| 0ebc | DUP1 | |
| 0ebd | PUSH2 | 0x0d37 |
| 0ec0 | JUMP | |
| 0ec1 | JUMPDEST | |
| 0ec2 | PUSH0 | |
| 0ec3 | PUSH2 | 0x0ecb |
| 0ec6 | SWAP2 | |
| 0ec7 | PUSH2 | 0x1be1 |
| 0eca | JUMP | |
| 0ecb | JUMPDEST | |
| 0ecc | DUP4 | |
| 0ecd | PUSH2 | 0x0eba |
| 0ed0 | JUMP | |
| 0ed1 | JUMPDEST | |
| 0ed2 | PUSH1 | 0xa3 |
| 0ed4 | NOT | |
| 0ed5 | DUP10 | |
| 0ed6 | DUP10 | |
| 0ed7 | SUB | |
| 0ed8 | ADD | |
| 0ed9 | DUP6 | |
| 0eda | MSTORE | |
| 0edb | SWAP5 | |
| 0edc | SWAP7 | |
| 0edd | SWAP4 | |
| 0ede | SWAP6 | |
| 0edf | POP | |
| 0ee0 | SWAP2 | |
| 0ee1 | SWAP4 | |
| 0ee2 | SWAP1 | |
| 0ee3 | SWAP3 | |
| 0ee4 | DUP7 | |
| 0ee5 | CALLDATALOAD | |
| 0ee6 | DUP3 | |
| 0ee7 | DUP2 | |
| 0ee8 | SLT | |
| 0ee9 | ISZERO | |
| 0eea | PUSH2 | 0x02ec |
| 0eed | JUMPI | |
| 0eee | DUP4 | |
| 0eef | ADD | |
| 0ef0 | PUSH1 | 0x01 |
| 0ef2 | PUSH1 | 0x01 |
| 0ef4 | PUSH1 | 0xa0 |
| 0ef6 | SHL | |
| 0ef7 | SUB | |
| 0ef8 | PUSH2 | 0x0f00 |
| 0efb | DUP3 | |
| 0efc | PUSH2 | 0x1a77 |
| 0eff | JUMP | |
| 0f00 | JUMPDEST | |
| 0f01 | AND | |
| 0f02 | DUP3 | |
| 0f03 | MSTORE | |
| 0f04 | PUSH1 | 0x20 |
| 0f06 | DUP2 | |
| 0f07 | ADD | |
| 0f08 | CALLDATALOAD | |
| 0f09 | SWAP2 | |
| 0f0a | PUSH1 | 0xff |
| 0f0c | DUP4 | |
| 0f0d | AND | |
| 0f0e | DUP1 | |
| 0f0f | SWAP4 | |
| 0f10 | SUB | |
| 0f11 | PUSH2 | 0x02ec |
| 0f14 | JUMPI | |
| 0f15 | PUSH2 | 0x0f36 |
| 0f18 | PUSH1 | 0x20 |
| 0f1a | SWAP3 | |
| 0f1b | DUP3 | |
| 0f1c | PUSH1 | 0x01 |
| 0f1e | SWAP6 | |
| 0f1f | DUP6 | |
| 0f20 | DUP1 | |
| 0f21 | SWAP6 | |
| 0f22 | ADD | |
| 0f23 | MSTORE | |
| 0f24 | PUSH2 | 0x0795 |
| 0f27 | PUSH2 | 0x078a |
| 0f2a | PUSH2 | 0x0779 |
| 0f2d | PUSH1 | 0x40 |
| 0f2f | DUP6 | |
| 0f30 | ADD | |
| 0f31 | DUP6 | |
| 0f32 | PUSH2 | 0x1f15 |
| 0f35 | JUMP | |
| 0f36 | JUMPDEST | |
| 0f37 | SWAP9 | |
| 0f38 | ADD | |
| 0f39 | SWAP7 | |
| 0f3a | ADD | |
| 0f3b | SWAP4 | |
| 0f3c | ADD | |
| 0f3d | SWAP1 | |
| 0f3e | SWAP2 | |
| 0f3f | DUP8 | |
| 0f40 | SWAP6 | |
| 0f41 | SWAP5 | |
| 0f42 | SWAP3 | |
| 0f43 | PUSH2 | 0x0e97 |
| 0f46 | JUMP | |
| 0f47 | JUMPDEST | |
| 0f48 | POP | |
| 0f49 | PUSH1 | 0x40 |
| 0f4b | MLOAD | |
| 0f4c | PUSH4 | 0xf5778b03 |
| 0f51 | PUSH1 | 0xe0 |
| 0f53 | SHL | |
| 0f54 | DUP2 | |
| 0f55 | MSTORE | |
| 0f56 | PUSH1 | 0x20 |
| 0f58 | DUP2 | |
| 0f59 | PUSH1 | 0x04 |
| 0f5b | DUP2 | |
| 0f5c | DUP9 | |
| 0f5d | GAS | |
| 0f5e | STATICCALL | |
| 0f5f | SWAP1 | |
| 0f60 | DUP2 | |
| 0f61 | ISZERO | |
| 0f62 | PUSH2 | 0x0708 |
| 0f65 | JUMPI | |
| 0f66 | PUSH0 | |
| 0f67 | SWAP2 | |
| 0f68 | PUSH2 | 0x0f7e |
| 0f6b | JUMPI | |
| 0f6c | JUMPDEST | |
| 0f6d | POP | |
| 0f6e | PUSH1 | 0x01 |
| 0f70 | PUSH1 | 0x01 |
| 0f72 | PUSH1 | 0xa0 |
| 0f74 | SHL | |
| 0f75 | SUB | |
| 0f76 | AND | |
| 0f77 | CALLER | |
| 0f78 | EQ | |
| 0f79 | ISZERO | |
| 0f7a | PUSH2 | 0x0d32 |
| 0f7d | JUMP | |
| 0f7e | JUMPDEST | |
| 0f7f | PUSH2 | 0x0f97 |
| 0f82 | SWAP2 | |
| 0f83 | POP | |
| 0f84 | PUSH1 | 0x20 |
| 0f86 | RETURNDATASIZE | |
| 0f87 | PUSH1 | 0x20 |
| 0f89 | GT | |
| 0f8a | PUSH2 | 0x0814 |
| 0f8d | JUMPI | |
| 0f8e | PUSH2 | 0x0806 |
| 0f91 | DUP2 | |
| 0f92 | DUP4 | |
| 0f93 | PUSH2 | 0x1be1 |
| 0f96 | JUMP | |
| 0f97 | JUMPDEST | |
| 0f98 | DUP8 | |
| 0f99 | PUSH2 | 0x0f6c |
| 0f9c | JUMP | |
| 0f9d | JUMPDEST | |
| 0f9e | PUSH2 | 0x0fb6 |
| 0fa1 | SWAP2 | |
| 0fa2 | POP | |
| 0fa3 | PUSH1 | 0x20 |
| 0fa5 | RETURNDATASIZE | |
| 0fa6 | PUSH1 | 0x20 |
| 0fa8 | GT | |
| 0fa9 | PUSH2 | 0x0843 |
| 0fac | JUMPI | |
| 0fad | PUSH2 | 0x0835 |
| 0fb0 | DUP2 | |
| 0fb1 | DUP4 | |
| 0fb2 | PUSH2 | 0x1be1 |
| 0fb5 | JUMP | |
| 0fb6 | JUMPDEST | |
| 0fb7 | DUP8 | |
| 0fb8 | PUSH2 | 0x0d2a |
| 0fbb | JUMP | |
| 0fbc | JUMPDEST | |
| 0fbd | CALLVALUE | |
| 0fbe | PUSH2 | 0x02ec |
| 0fc1 | JUMPI | |
| 0fc2 | PUSH0 | |
| 0fc3 | CALLDATASIZE | |
| 0fc4 | PUSH1 | 0x03 |
| 0fc6 | NOT | |
| 0fc7 | ADD | |
| 0fc8 | SLT | |
| 0fc9 | PUSH2 | 0x02ec |
| 0fcc | JUMPI | |
| 0fcd | PUSH1 | 0x20 |
| 0fcf | PUSH1 | 0x06 |
| 0fd1 | SLOAD | |
| 0fd2 | PUSH1 | 0x40 |
| 0fd4 | MLOAD | |
| 0fd5 | SWAP1 | |
| 0fd6 | DUP2 | |
| 0fd7 | MSTORE | |
| 0fd8 | RETURN | |
| 0fd9 | JUMPDEST | |
| 0fda | CALLVALUE | |
| 0fdb | PUSH2 | 0x02ec |
| 0fde | JUMPI | |
| 0fdf | PUSH0 | |
| 0fe0 | CALLDATASIZE | |
| 0fe1 | PUSH1 | 0x03 |
| 0fe3 | NOT | |
| 0fe4 | ADD | |
| 0fe5 | SLT | |
| 0fe6 | PUSH2 | 0x02ec |
| 0fe9 | JUMPI | |
| 0fea | PUSH1 | 0x40 |
| 0fec | PUSH1 | 0x07 |
| 0fee | SLOAD | |
| 0fef | PUSH1 | 0x06 |
| 0ff1 | SLOAD | |
| 0ff2 | DUP3 | |
| 0ff3 | MLOAD | |
| 0ff4 | SWAP2 | |
| 0ff5 | DUP3 | |
| 0ff6 | MSTORE | |
| 0ff7 | PUSH1 | 0x20 |
| 0ff9 | DUP3 | |
| 0ffa | ADD | |
| 0ffb | MSTORE | |
| 0ffc | RETURN | |
| 0ffd | JUMPDEST | |
| 0ffe | CALLVALUE | |
| 0fff | PUSH2 | 0x02ec |
| 1002 | JUMPI | |
| 1003 | PUSH0 | |
| 1004 | CALLDATASIZE | |
| 1005 | PUSH1 | 0x03 |
| 1007 | NOT | |
| 1008 | ADD | |
| 1009 | SLT | |
| 100a | PUSH2 | 0x02ec |
| 100d | JUMPI | |
| 100e | PUSH1 | 0x40 |
| 1010 | MLOAD | |
| 1011 | PUSH32 | 0x00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf |
| 1032 | PUSH1 | 0x01 |
| 1034 | PUSH1 | 0x01 |
| 1036 | PUSH1 | 0xa0 |
| 1038 | SHL | |
| 1039 | SUB | |
| 103a | AND | |
| 103b | DUP2 | |
| 103c | MSTORE | |
| 103d | PUSH1 | 0x20 |
| 103f | SWAP1 | |
| 1040 | RETURN | |
| 1041 | JUMPDEST | |
| 1042 | CALLVALUE | |
| 1043 | PUSH2 | 0x02ec |
| 1046 | JUMPI | |
| 1047 | PUSH0 | |
| 1048 | CALLDATASIZE | |
| 1049 | PUSH1 | 0x03 |
| 104b | NOT | |
| 104c | ADD | |
| 104d | SLT | |
| 104e | PUSH2 | 0x02ec |
| 1051 | JUMPI | |
| 1052 | PUSH1 | 0x20 |
| 1054 | PUSH1 | 0x40 |
| 1056 | MLOAD | |
| 1057 | PUSH32 | 0x405bbda3343b6e69c32fb7eafff8f0a1e55a5ee2ec35458b3abc776b26681952 |
| 1078 | DUP2 | |
| 1079 | MSTORE | |
| 107a | RETURN | |
| 107b | JUMPDEST | |
| 107c | CALLVALUE | |
| 107d | PUSH2 | 0x02ec |
| 1080 | JUMPI | |
| 1081 | PUSH1 | 0x20 |
| 1083 | CALLDATASIZE | |
| 1084 | PUSH1 | 0x03 |
| 1086 | NOT | |
| 1087 | ADD | |
| 1088 | SLT | |
| 1089 | PUSH2 | 0x02ec |
| 108c | JUMPI | |
| 108d | PUSH1 | 0x40 |
| 108f | PUSH2 | 0x1099 |
| 1092 | PUSH1 | 0x04 |
| 1094 | CALLDATALOAD | |
| 1095 | PUSH2 | 0x1ffa |
| 1098 | JUMP | |
| 1099 | JUMPDEST | |
| 109a | DUP3 | |
| 109b | MLOAD | |
| 109c | SWAP2 | |
| 109d | DUP3 | |
| 109e | MSTORE | |
| 109f | ISZERO | |
| 10a0 | ISZERO | |
| 10a1 | PUSH1 | 0x20 |
| 10a3 | DUP3 | |
| 10a4 | ADD | |
| 10a5 | MSTORE | |
| 10a6 | RETURN | |
| 10a7 | JUMPDEST | |
| 10a8 | CALLVALUE | |
| 10a9 | PUSH2 | 0x02ec |
| 10ac | JUMPI | |
| 10ad | PUSH1 | 0x20 |
| 10af | CALLDATASIZE | |
| 10b0 | PUSH1 | 0x03 |
| 10b2 | NOT | |
| 10b3 | ADD | |
| 10b4 | SLT | |
| 10b5 | PUSH2 | 0x02ec |
| 10b8 | JUMPI | |
| 10b9 | PUSH2 | 0x03b5 |
| 10bc | PUSH2 | 0x10c6 |
| 10bf | PUSH1 | 0x04 |
| 10c1 | CALLDATALOAD | |
| 10c2 | PUSH2 | 0x1f66 |
| 10c5 | JUMP | |
| 10c6 | JUMPDEST | |
| 10c7 | PUSH1 | 0x40 |
| 10c9 | MLOAD | |
| 10ca | SWAP2 | |
| 10cb | DUP3 | |
| 10cc | SWAP2 | |
| 10cd | PUSH1 | 0x20 |
| 10cf | DUP4 | |
| 10d0 | MSTORE | |
| 10d1 | PUSH1 | 0x20 |
| 10d3 | DUP4 | |
| 10d4 | ADD | |
| 10d5 | SWAP1 | |
| 10d6 | PUSH2 | 0x1ace |
| 10d9 | JUMP | |
| 10da | JUMPDEST | |
| 10db | CALLVALUE | |
| 10dc | PUSH2 | 0x02ec |
| 10df | JUMPI | |
| 10e0 | PUSH2 | 0x10e8 |
| 10e3 | CALLDATASIZE | |
| 10e4 | PUSH2 | 0x1b47 |
| 10e7 | JUMP | |
| 10e8 | JUMPDEST | |
| 10e9 | PUSH1 | 0x40 |
| 10eb | MLOAD | |
| 10ec | PUSH4 | 0x28305db1 |
| 10f1 | PUSH1 | 0xe2 |
| 10f3 | SHL | |
| 10f4 | DUP2 | |
| 10f5 | MSTORE | |
| 10f6 | SWAP4 | |
| 10f7 | SWAP5 | |
| 10f8 | SWAP4 | |
| 10f9 | PUSH32 | 0x00000000000000000000000070b4f3c06e5d93d695129f1255c55c01e7be13bf |
| 111a | PUSH1 | 0x01 |
| 111c | PUSH1 | 0x01 |
| 111e | PUSH1 | 0xa0 |
| 1120 | SHL | |
| 1121 | SUB | |
| 1122 | AND | |
| 1123 | SWAP3 | |
| 1124 | SWAP1 | |
| 1125 | PUSH1 | 0x20 |
| 1127 | DUP2 | |
| 1128 | PUSH1 | 0x04 |
| 112a | DUP2 | |
| 112b | DUP8 | |
| 112c | GAS | |
| 112d | STATICCALL | |
| 112e | SWAP1 | |
| 112f | DUP2 | |
| 1130 | ISZERO | |
| 1131 | PUSH2 | 0x0708 |
| 1134 | JUMPI | |
| 1135 | PUSH0 | |
| 1136 | SWAP2 | |
| 1137 | PUSH2 | 0x134f |
| 113a | JUMPI | |
| 113b | JUMPDEST | |
| 113c | POP | |
| 113d | DUP1 | |
| 113e | ISZERO | |
| 113f | PUSH2 | 0x12f9 |
| 1142 | JUMPI | |
| 1143 | JUMPDEST | |
| 1144 | PUSH2 | 0x11a6 |
| 1147 | JUMPI | |
| 1148 | JUMPDEST | |
| 1149 | POP | |
| 114a | POP | |
| 114b | POP | |
| 114c | POP | |
| 114d | PUSH1 | 0x06 |
| 114f | SLOAD | |
| 1150 | PUSH2 | 0x060a |
| 1153 | JUMPI | |
| 1154 | DUP2 | |
| 1155 | ISZERO | |
| 1156 | PUSH2 | 0x02dd |
| 1159 | JUMPI | |
| 115a | PUSH0 | |
| 115b | JUMPDEST | |
| 115c | DUP3 | |
| 115d | DUP2 | |
| 115e | LT | |
| 115f | PUSH2 | 0x118f |
| 1162 | JUMPI | |
| 1163 | PUSH32 | 0x1c295873c1ce4ce2ac720f43d6909e66b931b42e9246b862278eba9624c0bf05 |
| 1184 | PUSH1 | 0x20 |
| 1186 | DUP5 | |
| 1187 | PUSH1 | 0x40 |
| 1189 | MLOAD | |
| 118a | SWAP1 | |
| 118b | DUP2 | |
| 118c | MSTORE | |
| 118d | LOG1 | |
| 118e | STOP | |
| 118f | JUMPDEST | |
| 1190 | DUP1 | |
| 1191 | PUSH2 | 0x11a0 |
| 1194 | PUSH2 | 0x02c2 |
| 1197 | PUSH1 | 0x01 |
| 1199 | SWAP4 | |
| 119a | DUP7 | |
| 119b | DUP7 | |
| 119c | PUSH2 | 0x1eb5 |
| 119f | JUMP | |
| 11a0 | JUMPDEST | |
| 11a1 | ADD | |
| 11a2 | PUSH2 | 0x115b |
| 11a5 | JUMP | |
| 11a6 | JUMPDEST | |
| 11a7 | PUSH1 | 0x40 |
| 11a9 | MLOAD | |
| 11aa | PUSH1 | 0x20 |
| 11ac | DUP2 | |
| 11ad | ADD | |
| 11ae | SWAP1 | |
| 11af | PUSH1 | 0x20 |
| 11b1 | DUP3 | |
| 11b2 | MSTORE | |
| 11b3 | PUSH2 | 0x11c4 |
| 11b6 | DUP2 | |
| 11b7 | PUSH2 | 0x01d0 |
| 11ba | PUSH1 | 0x40 |
| 11bc | DUP3 | |
| 11bd | ADD | |
| 11be | DUP12 | |
| 11bf | DUP12 | |
| 11c0 | PUSH2 | 0x1e73 |
| 11c3 | JUMP | |
| 11c4 | JUMPDEST | |
| 11c5 | MLOAD | |
| 11c6 | SWAP1 | |
| 11c7 | KECCAK256 | |
| 11c8 | DUP4 | |
| 11c9 | EXTCODESIZE | |
| 11ca | ISZERO | |
| 11cb | PUSH2 | 0x02ec |
| 11ce | JUMPI | |
| 11cf | SWAP1 | |
| 11d0 | DUP3 | |
| 11d1 | PUSH1 | 0x01 |
| 11d3 | PUSH1 | 0x01 |
| 11d5 | PUSH1 | 0x40 |
| 11d7 | SHL | |
| 11d8 | SUB | |
| 11d9 | SWAP6 | |
| 11da | SWAP4 | |
| 11db | SWAP3 | |
| 11dc | PUSH1 | 0x40 |
| 11de | MLOAD | |
| 11df | SWAP7 | |
| 11e0 | DUP8 | |
| 11e1 | SWAP6 | |
| 11e2 | PUSH4 | 0x22f3f447 |
| 11e7 | PUSH1 | 0xe1 |
| 11e9 | SHL | |
| 11ea | DUP8 | |
| 11eb | MSTORE | |
| 11ec | PUSH1 | 0x84 |
| 11ee | DUP8 | |
| 11ef | ADD | |
| 11f0 | SWAP3 | |
| 11f1 | PUSH32 | 0x9abdf9961fd14fd177480eccbad16b2d7f231898b2d763c8e8b50364d8b3b171 |
| 1212 | PUSH1 | 0x04 |
| 1214 | DUP10 | |
| 1215 | ADD | |
| 1216 | MSTORE | |
| 1217 | PUSH1 | 0x24 |
| 1219 | DUP9 | |
| 121a | ADD | |
| 121b | MSTORE | |
| 121c | AND | |
| 121d | PUSH1 | 0x44 |
| 121f | DUP7 | |
| 1220 | ADD | |
| 1221 | MSTORE | |
| 1222 | PUSH1 | 0x80 |
| 1224 | PUSH1 | 0x64 |
| 1226 | DUP7 | |
| 1227 | ADD | |
| 1228 | MSTORE | |
| 1229 | MSTORE | |
| 122a | PUSH1 | 0xa4 |
| 122c | DUP4 | |
| 122d | ADD | |
| 122e | PUSH1 | 0xa0 |
| 1230 | PUSH1 | 0x04 |
| 1232 | DUP5 | |
| 1233 | PUSH1 | 0x05 |
| 1235 | SHL | |
| 1236 | DUP7 | |
| 1237 | ADD | |
| 1238 | ADD | |
| 1239 | ADD | |
| 123a | SWAP3 | |
| 123b | DUP3 | |
| 123c | PUSH0 | |
| 123d | SWAP1 | |
| 123e | PUSH1 | 0x7e |
| 1240 | NOT | |
| 1241 | DUP2 | |
| 1242 | CALLDATASIZE | |
| 1243 | SUB | |
| 1244 | ADD | |
| 1245 | JUMPDEST | |
| 1246 | DUP4 | |
| 1247 | DUP4 | |
| 1248 | LT | |
| 1249 | PUSH2 | 0x1281 |
| 124c | JUMPI | |
| 124d | POP | |
| 124e | POP | |
| 124f | POP | |
| 1250 | POP | |
| 1251 | POP | |
| 1252 | POP | |
| 1253 | SWAP2 | |
| 1254 | DUP2 | |
| 1255 | PUSH0 | |
| 1256 | DUP2 | |
| 1257 | DUP6 | |
| 1258 | DUP3 | |
| 1259 | SWAP7 | |
| 125a | POP | |
| 125b | SUB | |
| 125c | SWAP3 | |
| 125d | GAS | |
| 125e | CALL | |
| 125f | DUP1 | |
| 1260 | ISZERO | |
| 1261 | PUSH2 | 0x0708 |
| 1264 | JUMPI | |
| 1265 | PUSH2 | 0x1271 |
| 1268 | JUMPI | |
| 1269 | JUMPDEST | |
| 126a | DUP1 | |
| 126b | DUP1 | |
| 126c | DUP1 | |
| 126d | PUSH2 | 0x1148 |
| 1270 | JUMP | |
| 1271 | JUMPDEST | |
| 1272 | PUSH0 | |
| 1273 | PUSH2 | 0x127b |
| 1276 | SWAP2 | |
| 1277 | PUSH2 | 0x1be1 |
| 127a | JUMP | |
| 127b | JUMPDEST | |
| 127c | DUP3 | |
| 127d | PUSH2 | 0x1269 |
| 1280 | JUMP | |
| 1281 | JUMPDEST | |
| 1282 | PUSH1 | 0xa3 |
| 1284 | NOT | |
| 1285 | DUP11 | |
| 1286 | DUP9 | |
| 1287 | SUB | |
| 1288 | ADD | |
| 1289 | DUP6 | |
| 128a | MSTORE | |
| 128b | SWAP5 | |
| 128c | SWAP7 | |
| 128d | POP | |
| 128e | SWAP3 | |
| 128f | SWAP5 | |
| 1290 | SWAP2 | |
| 1291 | SWAP4 | |
| 1292 | SWAP1 | |
| 1293 | SWAP3 | |
| 1294 | SWAP2 | |
| 1295 | DUP7 | |
| 1296 | CALLDATALOAD | |
| 1297 | DUP3 | |
| 1298 | DUP2 | |
| 1299 | SLT | |
| 129a | ISZERO | |
| 129b | PUSH2 | 0x02ec |
| 129e | JUMPI | |
| 129f | DUP4 | |
| 12a0 | ADD | |
| 12a1 | PUSH1 | 0x01 |
| 12a3 | PUSH1 | 0x01 |
| 12a5 | PUSH1 | 0xa0 |
| 12a7 | SHL | |
| 12a8 | SUB | |
| 12a9 | PUSH2 | 0x12b1 |
| 12ac | DUP3 | |
| 12ad | PUSH2 | 0x1a77 |
| 12b0 | JUMP | |
| 12b1 | JUMPDEST | |
| 12b2 | AND | |
| 12b3 | DUP3 | |
| 12b4 | MSTORE | |
| 12b5 | PUSH1 | 0x20 |
| 12b7 | DUP2 | |
| 12b8 | ADD | |
| 12b9 | CALLDATALOAD | |
| 12ba | SWAP2 | |
| 12bb | PUSH1 | 0xff |
| 12bd | DUP4 | |
| 12be | AND | |
| 12bf | DUP1 | |
| 12c0 | SWAP4 | |
| 12c1 | SUB | |
| 12c2 | PUSH2 | 0x02ec |
| 12c5 | JUMPI | |
| 12c6 | PUSH2 | 0x12e7 |
| 12c9 | PUSH1 | 0x20 |
| 12cb | SWAP3 | |
| 12cc | DUP3 | |
| 12cd | PUSH1 | 0x01 |
| 12cf | SWAP6 | |
| 12d0 | DUP6 | |
| 12d1 | DUP1 | |
| 12d2 | SWAP6 | |
| 12d3 | ADD | |
| 12d4 | MSTORE | |
| 12d5 | PUSH2 | 0x0795 |
| 12d8 | PUSH2 | 0x078a |
| 12db | PUSH2 | 0x0779 |
| 12de | PUSH1 | 0x40 |
| 12e0 | DUP6 | |
| 12e1 | ADD | |
| 12e2 | DUP6 | |
| 12e3 | PUSH2 | 0x1f15 |
| 12e6 | JUMP | |
| 12e7 | JUMPDEST | |
| 12e8 | SWAP9 | |
| 12e9 | ADD | |
| 12ea | SWAP7 | |
| 12eb | ADD | |
| 12ec | SWAP4 | |
| 12ed | ADD | |
| 12ee | SWAP1 | |
| 12ef | SWAP2 | |
| 12f0 | DUP9 | |
| 12f1 | SWAP7 | |
| 12f2 | SWAP6 | |
| 12f3 | SWAP5 | |
| 12f4 | SWAP3 | |
| 12f5 | PUSH2 | 0x1245 |
| 12f8 | JUMP | |
| 12f9 | JUMPDEST | |
| 12fa | POP | |
| 12fb | PUSH1 | 0x40 |
| 12fd | MLOAD | |
| 12fe | PUSH4 | 0xf5778b03 |
| 1303 | PUSH1 | 0xe0 |
| 1305 | SHL | |
| 1306 | DUP2 | |
| 1307 | MSTORE | |
| 1308 | PUSH1 | 0x20 |
| 130a | DUP2 | |
| 130b | PUSH1 | 0x04 |
| 130d | DUP2 | |
| 130e | DUP8 | |
| 130f | GAS | |
| 1310 | STATICCALL | |
| 1311 | SWAP1 | |
| 1312 | DUP2 | |
| 1313 | ISZERO | |
| 1314 | PUSH2 | 0x0708 |
| 1317 | JUMPI | |
| 1318 | PUSH0 | |
| 1319 | SWAP2 | |
| 131a | PUSH2 | 0x1330 |
| 131d | JUMPI | |
| 131e | JUMPDEST | |
| 131f | POP | |
| 1320 | PUSH1 | 0x01 |
| 1322 | PUSH1 | 0x01 |
| 1324 | PUSH1 | 0xa0 |
| 1326 | SHL | |
| 1327 | SUB | |
| 1328 | AND | |
| 1329 | CALLER | |
| 132a | EQ | |
| 132b | ISZERO | |
| 132c | PUSH2 | 0x1143 |
| 132f | JUMP | |
| 1330 | JUMPDEST | |
| 1331 | PUSH2 | 0x1349 |
| 1334 | SWAP2 | |
| 1335 | POP | |
| 1336 | PUSH1 | 0x20 |
| 1338 | RETURNDATASIZE | |
| 1339 | PUSH1 | 0x20 |
| 133b | GT | |
| 133c | PUSH2 | 0x0814 |
| 133f | JUMPI | |
| 1340 | PUSH2 | 0x0806 |
| 1343 | DUP2 | |
| 1344 | DUP4 | |
| 1345 | PUSH2 | 0x1be1 |
| 1348 | JUMP | |
| 1349 | JUMPDEST | |
| 134a | DUP8 | |
| 134b | PUSH2 | 0x131e |
| 134e | JUMP | |
| 134f | JUMPDEST | |
| 1350 | PUSH2 | 0x1368 |
| 1353 | SWAP2 | |
| 1354 | POP | |
| 1355 | PUSH1 | 0x20 |
| 1357 | RETURNDATASIZE | |
| 1358 | PUSH1 | 0x20 |
| 135a | GT | |
| 135b | PUSH2 | 0x0843 |
| 135e | JUMPI | |
| 135f | PUSH2 | 0x0835 |
| 1362 | DUP2 | |
| 1363 | DUP4 | |
| 1364 | PUSH2 | 0x1be1 |
| 1367 | JUMP | |
| 1368 | JUMPDEST | |
| 1369 | DUP8 | |
| 136a | PUSH2 | 0x113b |
| 136d | JUMP | |
| 136e | JUMPDEST | |
| 136f | CALLVALUE | |
| 1370 | PUSH2 | 0x02ec |
| 1373 | JUMPI | |
| 1374 | PUSH1 | 0x60 |
| 1376 | CALLDATASIZE | |
| 1377 | PUSH1 | 0x03 |
| 1379 | NOT | |
| 137a | ADD | |
| 137b | SLT | |
| 137c | PUSH2 | 0x02ec |
| 137f | JUMPI | |
| 1380 | PUSH1 | 0x04 |
| 1382 | CALLDATALOAD | |
| 1383 | PUSH1 | 0x04 |
| 1385 | DUP2 | |
| 1386 | LT | |
| 1387 | ISZERO | |
| 1388 | PUSH2 | 0x02ec |
| 138b | JUMPI | |
| 138c | PUSH2 | 0x0884 |
| 138f | PUSH1 | 0x20 |
| 1391 | SWAP2 | |
| 1392 | PUSH2 | 0x1399 |
| 1395 | PUSH2 | 0x1a61 |
| 1398 | JUMP | |
| 1399 | JUMPDEST | |
| 139a | PUSH1 | 0x44 |
| 139c | CALLDATALOAD | |
| 139d | SWAP2 | |
| 139e | PUSH2 | 0x1ec5 |
| 13a1 | JUMP | |
| 13a2 | JUMPDEST | |
| 13a3 | CALLVALUE | |
| 13a4 | PUSH2 | 0x02ec |
| 13a7 | JUMPI | |
| 13a8 | PUSH0 | |
| 13a9 | CALLDATASIZE | |
| 13aa | PUSH1 | 0x03 |
| 13ac | NOT | |
| 13ad | ADD | |
| 13ae | SLT | |
| 13af | PUSH2 | 0x02ec |
| 13b2 | JUMPI | |
| 13b3 | PUSH2 | 0x03b5 |
| 13b6 | PUSH2 | 0x10c6 |
| 13b9 | PUSH1 | 0x06 |
| 13bb | SLOAD | |
| 13bc | PUSH2 | 0x1f66 |
| 13bf | JUMP | |
| 13c0 | JUMPDEST | |
| 13c1 | CALLVALUE | |
| 13c2 | PUSH2 | 0x02ec |
| 13c5 | JUMPI | |
| 13c6 | PUSH0 | |
| 13c7 | CALLDATASIZE | |
| 13c8 | PUSH1 | 0x03 |
| 13ca | NOT | |
| 13cb | ADD | |
| 13cc | SLT | |
| 13cd | PUSH2 | 0x02ec |
| 13d0 | JUMPI | |
| 13d1 | PUSH1 | 0x20 |
| 13d3 | PUSH1 | 0x40 |
| 13d5 | MLOAD | |
| 13d6 | PUSH32 | 0xb66ca34dc0d9a9daa6230aee35894330ccfa7e4eaa29a198577eed0b26a41205 |
| 13f7 | DUP2 | |
| 13f8 | MSTORE | |
| 13f9 | RETURN | |
| 13fa | JUMPDEST | |
| 13fb | CALLVALUE | |
| 13fc | PUSH2 | 0x02ec |
| 13ff | JUMPI | |
| 1400 | PUSH2 | 0x1408 |
| 1403 | CALLDATASIZE | |
| 1404 | PUSH2 | 0x1ab8 |
| 1407 | JUMP | |
| 1408 | JUMPDEST | |
| 1409 | PUSH2 | 0x1424 |
| 140c | PUSH2 | 0x141e |
| 140f | PUSH2 | 0x1418 |
| 1412 | DUP4 | |
| 1413 | DUP6 | |
| 1414 | PUSH2 | 0x1c94 |
| 1417 | JUMP | |
| 1418 | JUMPDEST | |
| 1419 | SWAP4 | |
| 141a | PUSH2 | 0x1bac |
| 141d | JUMP | |
| 141e | JUMPDEST | |
| 141f | SWAP2 | |
| 1420 | PUSH2 | 0x206e |
| 1423 | JUMP | |
| 1424 | JUMPDEST | |
| 1425 | PUSH2 | 0x1440 |
| 1428 | PUSH1 | 0x40 |
| 142a | MLOAD | |
| 142b | SWAP4 | |
| 142c | DUP5 | |
| 142d | SWAP4 | |
| 142e | DUP5 | |
| 142f | MSTORE | |
| 1430 | PUSH1 | 0x60 |
| 1432 | PUSH1 | 0x20 |
| 1434 | DUP6 | |
| 1435 | ADD | |
| 1436 | MSTORE | |
| 1437 | PUSH1 | 0x60 |
| 1439 | DUP5 | |
| 143a | ADD | |
| 143b | SWAP1 | |
| 143c | PUSH2 | 0x1ace |
| 143f | JUMP | |
| 1440 | JUMPDEST | |
| 1441 | SWAP1 | |
| 1442 | PUSH1 | 0x40 |
| 1444 | DUP4 | |
| 1445 | ADD | |
| 1446 | MSTORE | |
| 1447 | SUB | |
| 1448 | SWAP1 | |
| 1449 | RETURN | |
| 144a | JUMPDEST | |
| 144b | CALLVALUE | |
| 144c | PUSH2 | 0x02ec |
| 144f | JUMPI | |
| 1450 | PUSH0 | |
| 1451 | CALLDATASIZE | |
| 1452 | PUSH1 | 0x03 |
| 1454 | NOT | |
| 1455 | ADD | |
| 1456 | SLT | |
| 1457 | PUSH2 | 0x02ec |
| 145a | JUMPI | |
| 145b | PUSH1 | 0x20 |
| 145d | PUSH1 | 0x01 |
| 145f | SLOAD | |
| 1460 | PUSH1 | 0x40 |
| 1462 | MLOAD | |
| 1463 | SWAP1 | |
| 1464 | DUP2 | |
| 1465 | MSTORE | |
| 1466 | RETURN | |
| 1467 | JUMPDEST | |
| 1468 | CALLVALUE | |
| 1469 | PUSH2 | 0x02ec |
| 146c | JUMPI | |
| 146d | PUSH1 | 0x80 |
| 146f | CALLDATASIZE | |
| 1470 | PUSH1 | 0x03 |
| 1472 | NOT | |
| 1473 | ADD | |
| 1474 | SLT | |
| 1475 | PUSH2 | 0x02ec |
| 1478 | JUMPI | |
| 1479 | PUSH1 | 0x04 |
| 147b | CALLDATALOAD | |
| 147c | PUSH1 | 0x01 |
| 147e | PUSH1 | 0x01 |
| 1480 | PUSH1 | 0x40 |
| 1482 | SHL | |
| 1483 | SUB | |
| 1484 | DUP2 | |
| 1485 | GT | |
| 1486 | PUSH2 | 0x02ec |
| 1489 | JUMPI | |
| 148a | PUSH2 | 0x1497 |
| 148d | SWAP1 | |
| 148e | CALLDATASIZE | |
| 148f | SWAP1 | |
| 1490 | PUSH1 | 0x04 |
| 1492 | ADD | |
| 1493 | PUSH2 | 0x1b01 |
| 1496 | JUMP | |
| 1497 | JUMPDEST | |
| 1498 | SWAP1 | |
| 1499 | PUSH1 | 0x24 |
| 149b | CALLDATALOAD | |
| 149c | PUSH1 | 0x01 |
| 149e | PUSH1 | 0x01 |
| 14a0 | PUSH1 | 0x40 |
| 14a2 | SHL | |
| 14a3 | SUB | |
| 14a4 | DUP2 | |
| 14a5 | GT | |
| 14a6 | PUSH2 | 0x02ec |
| 14a9 | JUMPI | |
| 14aa | PUSH2 | 0x14b7 |
| 14ad | SWAP1 | |
| 14ae | CALLDATASIZE | |
| 14af | SWAP1 | |
| 14b0 | PUSH1 | 0x04 |
| 14b2 | ADD | |
| 14b3 | PUSH2 | 0x1b01 |
| 14b6 | JUMP | |
| 14b7 | JUMPDEST | |
| 14b8 | PUSH2 | 0x14c2 |
| 14bb | SWAP4 | |
| 14bc | SWAP2 | |
| 14bd | SWAP4 | |
| 14be | PUSH2 | 0x1b31 |
| 14c1 | JUMP | |
| 14c2 | JUMPDEST | |
| 14c3 | SWAP4 | |
| 14c4 | PUSH1 | 0x64 |
| 14c6 | CALLDATALOAD | |
| 14c7 | PUSH1 | 0x01 |
| 14c9 | PUSH1 | 0x01 |
| 14cb | PUSH1 | 0x40 |
| 14cd | SHL | |
| 14ce | SUB | |
| 14cf | DUP2 | |
| 14d0 | GT | |
| 14d1 | PUSH2 | 0x02ec |
| 14d4 | JUMPI | |
| 14d5 | PUSH2 | 0x14e2 |
| 14d8 | SWAP1 | |
| 14d9 | CALLDATASIZE | |
| 14da | SWAP1 | |
| 14db | PUSH1 | 0x04 |
| 14dd | ADD | |
| 14de | PUSH2 | 0x1b01 |
| 14e1 | JUMP | |
| 14e2 | JUMPDEST | |
| 14e3 | SWAP6 | |
| 14e4 | DUP4 | |
| 14e5 | ISZERO | |
| 14e6 | PUSH2 | 0x02dd |
| 14e9 | JUMPI | |
| 14ea | DUP4 | |
| 14eb | DUP6 | |
| 14ec | SUB | |
| 14ed | PUSH2 | 0x196e |
| 14f0 | JUMPI | |
| 14f1 | PUSH1 | 0x01 |
| 14f3 | SLOAD | |
| 14f4 | DUP1 | |
| 14f5 | ISZERO | |
| 14f6 | PUSH2 | 0x02ce |
| 14f9 | JUMPI | |
| 14fa | PUSH1 | 0x02 |
| 14fc | SWAP8 | |
| 14fd | SWAP6 | |
| 14fe | SWAP8 | |
| 14ff | SWAP7 | |
| 1500 | SWAP4 | |
| 1501 | SWAP7 | |
| 1502 | SLOAD | |
| 1503 | SWAP3 | |
| 1504 | PUSH1 | 0x06 |
| 1506 | SLOAD | |
| 1507 | SWAP7 | |
| 1508 | PUSH1 | 0x40 |
| 150a | MLOAD | |
| 150b | PUSH1 | 0x01 |
| 150d | PUSH1 | 0x01 |
| 150f | PUSH1 | 0x40 |
| 1511 | SHL | |
| 1512 | SUB | |
| 1513 | DUP7 | |
| 1514 | AND | |
| 1515 | PUSH1 | 0x20 |
| 1517 | DUP3 | |
| 1518 | ADD | |
| 1519 | MSTORE | |
| 151a | DUP9 | |
| 151b | PUSH1 | 0x40 |
| 151d | DUP3 | |
| 151e | ADD | |
| 151f | MSTORE | |
| 1520 | PUSH1 | 0x80 |
| 1522 | PUSH1 | 0x60 |
| 1524 | DUP3 | |
| 1525 | ADD | |
| 1526 | MSTORE | |
| 1527 | PUSH2 | 0x1534 |
| 152a | PUSH1 | 0xa0 |
| 152c | DUP3 | |
| 152d | ADD | |
| 152e | DUP13 | |
| 152f | DUP10 | |
| 1530 | PUSH2 | 0x1e73 |
| 1533 | JUMP | |
| 1534 | JUMPDEST | |
| 1535 | PUSH1 | 0x1f |
| 1537 | NOT | |
| 1538 | DUP3 | |
| 1539 | DUP3 | |
| 153a | SUB | |
| 153b | ADD | |
| 153c | PUSH1 | 0x80 |
| 153e | DUP4 | |
| 153f | ADD | |
| 1540 | MSTORE | |
| 1541 | DUP9 | |
| 1542 | DUP2 | |
| 1543 | MSTORE | |
| 1544 | PUSH1 | 0x20 |
| 1546 | DUP2 | |
| 1547 | ADD | |
| 1548 | SWAP1 | |
| 1549 | PUSH1 | 0x20 |
| 154b | DUP11 | |
| 154c | PUSH1 | 0x05 |
| 154e | SHL | |
| 154f | DUP3 | |
| 1550 | ADD | |
| 1551 | ADD | |
| 1552 | SWAP2 | |
| 1553 | DUP13 | |
| 1554 | SWAP2 | |
| 1555 | PUSH0 | |
| 1556 | JUMPDEST | |
| 1557 | DUP13 | |
| 1558 | DUP2 | |
| 1559 | LT | |
| 155a | PUSH2 | 0x1902 |
| 155d | JUMPI | |
| 155e | POP | |
| 155f | POP | |
| 1560 | POP | |
| 1561 | POP | |
| 1562 | SWAP1 | |
| 1563 | PUSH2 | 0x157c |
| 1566 | DUP2 | |
| 1567 | PUSH2 | 0x1603 |
| 156a | SWAP8 | |
| 156b | SWAP7 | |
| 156c | SWAP6 | |
| 156d | SWAP5 | |
| 156e | SWAP4 | |
| 156f | SUB | |
| 1570 | PUSH1 | 0x1f |
| 1572 | NOT | |
| 1573 | DUP2 | |
| 1574 | ADD | |
| 1575 | DUP4 | |
| 1576 | MSTORE | |
| 1577 | DUP3 | |
| 1578 | PUSH2 | 0x1be1 |
| 157b | JUMP | |
| 157c | JUMPDEST | |
| 157d | PUSH1 | 0x20 |
| 157f | DUP2 | |
| 1580 | MLOAD | |
| 1581 | SWAP2 | |
| 1582 | ADD | |
| 1583 | KECCAK256 | |
| 1584 | PUSH1 | 0x40 |
| 1586 | MLOAD | |
| 1587 | PUSH1 | 0x20 |
| 1589 | DUP2 | |
| 158a | ADD | |
| 158b | SWAP2 | |
| 158c | PUSH32 | 0xd850f5df47b124511e8e6ec99cf1a0beaf7c6237eff0a31305ce53d85f312675 |
| 15ad | DUP4 | |
| 15ae | MSTORE | |
| 15af | CHAINID | |
| 15b0 | PUSH1 | 0x40 |
| 15b2 | DUP4 | |
| 15b3 | ADD | |
| 15b4 | MSTORE | |
| 15b5 | ADDRESS | |
| 15b6 | PUSH1 | 0x60 |
| 15b8 | DUP4 | |
| 15b9 | ADD | |
| 15ba | MSTORE | |
| 15bb | PUSH32 | 0x2e1c2ff2f9bb13fd926fe3e8b209f98e6c873bb259534a2148ca355409247cba |
| 15dc | PUSH1 | 0x80 |
| 15de | DUP4 | |
| 15df | ADD | |
| 15e0 | MSTORE | |
| 15e1 | PUSH1 | 0x01 |
| 15e3 | PUSH1 | 0x01 |
| 15e5 | PUSH1 | 0x40 |
| 15e7 | SHL | |
| 15e8 | SUB | |
| 15e9 | DUP8 | |
| 15ea | AND | |
| 15eb | PUSH1 | 0xa0 |
| 15ed | DUP4 | |
| 15ee | ADD | |
| 15ef | MSTORE | |
| 15f0 | PUSH1 | 0xc0 |
| 15f2 | DUP3 | |
| 15f3 | ADD | |
| 15f4 | MSTORE | |
| 15f5 | PUSH1 | 0xc0 |
| 15f7 | DUP2 | |
| 15f8 | MSTORE | |
| 15f9 | PUSH2 | 0x025a |
| 15fc | PUSH1 | 0xe0 |
| 15fe | DUP3 | |
| 15ff | PUSH2 | 0x1be1 |
| 1602 | JUMP | |
| 1603 | JUMPDEST | |
| 1604 | POP | |
| 1605 | PUSH1 | 0x01 |
| 1607 | PUSH1 | 0x01 |
| 1609 | PUSH1 | 0x40 |
| 160b | SHL | |
| 160c | SUB | |
| 160d | PUSH2 | 0x1617 |
| 1610 | DUP2 | |
| 1611 | DUP4 | |
| 1612 | AND | |
| 1613 | PUSH2 | 0x1e97 |
| 1616 | JUMP | |
| 1617 | JUMPDEST | |
| 1618 | PUSH8 | 0xffffffffffffffff |
| 1621 | NOT | |
| 1622 | SWAP1 | |
| 1623 | SWAP3 | |
| 1624 | AND | |
| 1625 | SWAP2 | |
| 1626 | AND | |
| 1627 | OR | |
| 1628 | PUSH1 | 0x02 |
| 162a | SSTORE | |
| 162b | PUSH0 | |
| 162c | SWAP5 | |
| 162d | PUSH32 | 0x000000000000000000000000c0876d136341091581a489ce7f746692dddf498f |
| 164e | PUSH1 | 0x01 |
| 1650 | PUSH1 | 0x01 |
| 1652 | PUSH1 | 0xa0 |
| 1654 | SHL | |
| 1655 | SUB | |
| 1656 | AND | |
| 1657 | JUMPDEST | |
| 1658 | DUP4 | |
| 1659 | DUP8 | |
| 165a | LT | |
| 165b | ISZERO | |
| 165c | PUSH2 | 0x18f7 |
| 165f | JUMPI | |
| 1660 | DUP7 | |
| 1661 | PUSH1 | 0x05 |
| 1663 | SHL | |
| 1664 | DUP7 | |
| 1665 | ADD | |
| 1666 | CALLDATALOAD | |
| 1667 | PUSH1 | 0x1e |
| 1669 | NOT | |
| 166a | DUP8 | |
| 166b | CALLDATASIZE | |
| 166c | SUB | |
| 166d | ADD | |
| 166e | DUP2 | |
| 166f | SLT | |
| 1670 | ISZERO | |
| 1671 | PUSH2 | 0x02ec |
| 1674 | JUMPI | |
| 1675 | DUP7 | |
| 1676 | ADD | |
| 1677 | DUP1 | |
| 1678 | CALLDATALOAD | |
| 1679 | SWAP1 | |
| 167a | PUSH1 | 0x01 |
| 167c | PUSH1 | 0x01 |
| 167e | PUSH1 | 0x40 |
| 1680 | SHL | |
| 1681 | SUB | |
| 1682 | DUP3 | |
| 1683 | GT | |
| 1684 | PUSH2 | 0x02ec |
| 1687 | JUMPI | |
| 1688 | PUSH1 | 0x20 |
| 168a | ADD | |
| 168b | SWAP1 | |
| 168c | DUP1 | |
| 168d | PUSH1 | 0x05 |
| 168f | SHL | |
| 1690 | CALLDATASIZE | |
| 1691 | SUB | |
| 1692 | DUP3 | |
| 1693 | SGT | |
| 1694 | PUSH2 | 0x02ec |
| 1697 | JUMPI | |
| 1698 | DUP1 | |
| 1699 | ISZERO | |
| 169a | PUSH2 | 0x18e4 |
| 169d | JUMPI | |
| 169e | PUSH2 | 0x16a8 |
| 16a1 | DUP10 | |
| 16a2 | DUP6 | |
| 16a3 | DUP8 | |
| 16a4 | PUSH2 | 0x1eb5 |
| 16a7 | JUMP | |
| 16a8 | JUMPDEST | |
| 16a9 | CALLDATALOAD | |
| 16aa | ISZERO | |
| 16ab | PUSH2 | 0x18d1 |
| 16ae | JUMPI | |
| 16af | PUSH1 | 0x01 |
| 16b1 | DUP2 | |
| 16b2 | ADD | |
| 16b3 | DUP1 | |
| 16b4 | DUP3 | |
| 16b5 | GT | |
| 16b6 | PUSH2 | 0x0509 |
| 16b9 | JUMPI | |
| 16ba | PUSH2 | 0x16c2 |
| 16bd | SWAP1 | |
| 16be | PUSH2 | 0x1c2d |
| 16c1 | JUMP | |
| 16c2 | JUMPDEST | |
| 16c3 | SWAP2 | |
| 16c4 | PUSH2 | 0x16ce |
| 16c7 | DUP11 | |
| 16c8 | DUP7 | |
| 16c9 | DUP9 | |
| 16ca | PUSH2 | 0x1eb5 |
| 16cd | JUMP | |
| 16ce | JUMPDEST | |
| 16cf | CALLDATALOAD | |
| 16d0 | PUSH2 | 0x16d8 |
| 16d3 | DUP5 | |
| 16d4 | PUSH2 | 0x1c5f |
| 16d7 | JUMP | |
| 16d8 | JUMPDEST | |
| 16d9 | MSTORE | |
| 16da | PUSH0 | |
| 16db | JUMPDEST | |
| 16dc | DUP3 | |
| 16dd | DUP2 | |
| 16de | LT | |
| 16df | PUSH2 | 0x185a |
| 16e2 | JUMPI | |
| 16e3 | POP | |
| 16e4 | POP | |
| 16e5 | POP | |
| 16e6 | DUP1 | |
| 16e7 | MLOAD | |
| 16e8 | ISZERO | |
| 16e9 | PUSH2 | 0x184b |
| 16ec | JUMPI | |
| 16ed | JUMPDEST | |
| 16ee | DUP1 | |
| 16ef | MLOAD | |
| 16f0 | PUSH1 | 0x01 |
| 16f2 | DUP2 | |
| 16f3 | GT | |
| 16f4 | ISZERO | |
| 16f5 | PUSH2 | 0x181f |
| 16f8 | JUMPI | |
| 16f9 | DUP1 | |
| 16fa | PUSH1 | 0x01 |
| 16fc | SHR | |
| 16fd | SWAP1 | |
| 16fe | PUSH1 | 0x01 |
| 1700 | DUP2 | |
| 1701 | AND | |
| 1702 | SWAP3 | |
| 1703 | PUSH2 | 0x170f |
| 1706 | PUSH2 | 0x0390 |
| 1709 | DUP6 | |
| 170a | DUP6 | |
| 170b | PUSH2 | 0x1bd4 |
| 170e | JUMP | |
| 170f | JUMPDEST | |
| 1710 | SWAP4 | |
| 1711 | PUSH0 | |
| 1712 | JUMPDEST | |
| 1713 | DUP5 | |
| 1714 | DUP2 | |
| 1715 | LT | |
| 1716 | PUSH2 | 0x179f |
| 1719 | JUMPI | |
| 171a | POP | |
| 171b | PUSH1 | 0x01 |
| 171d | EQ | |
| 171e | PUSH2 | 0x172a |
| 1721 | JUMPI | |
| 1722 | JUMPDEST | |
| 1723 | POP | |
| 1724 | POP | |
| 1725 | POP | |
| 1726 | PUSH2 | 0x16ed |
| 1729 | JUMP | |
| 172a | JUMPDEST | |
| 172b | PUSH0 | |
| 172c | NOT | |
| 172d | DUP3 | |
| 172e | ADD | |
| 172f | SWAP2 | |
| 1730 | DUP3 | |
| 1731 | GT | |
| 1732 | PUSH2 | 0x0509 |
| 1735 | JUMPI | |
| 1736 | PUSH2 | 0x1796 |
| 1739 | SWAP2 | |
| 173a | PUSH2 | 0x1742 |
| 173d | SWAP2 | |
| 173e | PUSH2 | 0x1c80 |
| 1741 | JUMP | |
| 1742 | JUMPDEST | |
| 1743 | MLOAD | |
| 1744 | PUSH1 | 0x40 |
| 1746 | MLOAD | |
| 1747 | PUSH1 | 0x20 |
| 1749 | DUP2 | |
| 174a | ADD | |
| 174b | SWAP2 | |
| 174c | PUSH1 | 0x01 |
| 174e | PUSH1 | 0xf9 |
| 1750 | SHL | |
| 1751 | DUP4 | |
| 1752 | MSTORE | |
| 1753 | PUSH32 | 0xc976f483968b324bd57de8efa226478a3634db61776dacd4da866f8fa37c0fd5 |
| 1774 | PUSH1 | 0x21 |
| 1776 | DUP4 | |
| 1777 | ADD | |
| 1778 | MSTORE | |
| 1779 | PUSH1 | 0x41 |
| 177b | DUP3 | |
| 177c | ADD | |
| 177d | MSTORE | |
| 177e | PUSH1 | 0x41 |
| 1780 | DUP2 | |
| 1781 | MSTORE | |
| 1782 | PUSH2 | 0x178c |
| 1785 | PUSH1 | 0x61 |
| 1787 | DUP3 | |
| 1788 | PUSH2 | 0x1be1 |
| 178b | JUMP | |
| 178c | JUMPDEST | |
| 178d | MLOAD | |
| 178e | SWAP1 | |
| 178f | KECCAK256 | |
| 1790 | SWAP2 | |
| 1791 | DUP4 | |
| 1792 | PUSH2 | 0x1c80 |
| 1795 | JUMP | |
| 1796 | JUMPDEST | |
| 1797 | MSTORE | |
| 1798 | DUP9 | |
| 1799 | DUP1 | |
| 179a | DUP1 | |
| 179b | PUSH2 | 0x1722 |
| 179e | JUMP | |
| 179f | JUMPDEST | |
| 17a0 | DUP1 | |
| 17a1 | PUSH1 | 0x01 |
| 17a3 | SWAP2 | |
| 17a4 | DUP3 | |
| 17a5 | SHL | |
| 17a6 | PUSH2 | 0x17bc |
| 17a9 | DUP4 | |
| 17aa | PUSH2 | 0x17b3 |
| 17ad | DUP4 | |
| 17ae | DUP9 | |
| 17af | PUSH2 | 0x1c80 |
| 17b2 | JUMP | |
| 17b3 | JUMPDEST | |
| 17b4 | MLOAD | |
| 17b5 | SWAP3 | |
| 17b6 | OR | |
| 17b7 | DUP7 | |
| 17b8 | PUSH2 | 0x1c80 |
| 17bb | JUMP | |
| 17bc | JUMPDEST | |
| 17bd | MLOAD | |
| 17be | PUSH1 | 0x40 |
| 17c0 | MLOAD | |
| 17c1 | SWAP1 | |
| 17c2 | PUSH1 | 0x20 |
| 17c4 | DUP3 | |
| 17c5 | ADD | |
| 17c6 | SWAP3 | |
| 17c7 | DUP6 | |
| 17c8 | PUSH1 | 0xf8 |
| 17ca | SHL | |
| 17cb | DUP5 | |
| 17cc | MSTORE | |
| 17cd | PUSH32 | 0xc976f483968b324bd57de8efa226478a3634db61776dacd4da866f8fa37c0fd5 |
| 17ee | PUSH1 | 0x21 |
| 17f0 | DUP5 | |
| 17f1 | ADD | |
| 17f2 | MSTORE | |
| 17f3 | PUSH1 | 0x41 |
| 17f5 | DUP4 | |
| 17f6 | ADD | |
| 17f7 | MSTORE | |
| 17f8 | PUSH1 | 0x61 |
| 17fa | DUP3 | |
| 17fb | ADD | |
| 17fc | MSTORE | |
| 17fd | PUSH1 | 0x61 |
| 17ff | DUP2 | |
| 1800 | MSTORE | |
| 1801 | PUSH2 | 0x180b |
| 1804 | PUSH1 | 0x81 |
| 1806 | DUP3 | |
| 1807 | PUSH2 | 0x1be1 |
| 180a | JUMP | |
| 180b | JUMPDEST | |
| 180c | MLOAD | |
| 180d | SWAP1 | |
| 180e | KECCAK256 | |
| 180f | PUSH2 | 0x1818 |
| 1812 | DUP3 | |
| 1813 | DUP10 | |
| 1814 | PUSH2 | 0x1c80 |
| 1817 | JUMP | |
| 1818 | JUMPDEST | |
| 1819 | MSTORE | |
| 181a | ADD | |
| 181b | PUSH2 | 0x1712 |
| 181e | JUMP | |
| 181f | JUMPDEST | |
| 1820 | POP | |
| 1821 | SWAP7 | |
| 1822 | PUSH2 | 0x183d |
| 1825 | PUSH2 | 0x1837 |
| 1828 | PUSH1 | 0x01 |
| 182a | SWAP4 | |
| 182b | SWAP7 | |
| 182c | SWAP10 | |
| 182d | SWAP9 | |
| 182e | SWAP6 | |
| 182f | SWAP9 | |
| 1830 | SWAP8 | |
| 1831 | SWAP5 | |
| 1832 | SWAP8 | |
| 1833 | PUSH2 | 0x1c5f |
| 1836 | JUMP | |
| 1837 | JUMPDEST | |
| 1838 | MLOAD | |
| 1839 | PUSH2 | 0x2436 |
| 183c | JUMP | |
| 183d | JUMPDEST | |
| 183e | ADD | |
| 183f | SWAP6 | |
| 1840 | SWAP3 | |
| 1841 | SWAP5 | |
| 1842 | SWAP2 | |
| 1843 | SWAP5 | |
| 1844 | SWAP4 | |
| 1845 | SWAP1 | |
| 1846 | SWAP4 | |
| 1847 | PUSH2 | 0x1657 |
| 184a | JUMP | |
| 184b | JUMPDEST | |
| 184c | PUSH4 | 0x4f297b61 |
| 1851 | PUSH1 | 0xe1 |
| 1853 | SHL | |
| 1854 | PUSH0 | |
| 1855 | MSTORE | |
| 1856 | PUSH1 | 0x04 |
| 1858 | PUSH0 | |
| 1859 | REVERT | |
| 185a | JUMPDEST | |
| 185b | PUSH2 | 0x1865 |
| 185e | DUP2 | |
| 185f | DUP5 | |
| 1860 | DUP5 | |
| 1861 | PUSH2 | 0x1eb5 |
| 1864 | JUMP | |
| 1865 | JUMPDEST | |
| 1866 | CALLDATALOAD | |
| 1867 | DUP6 | |
| 1868 | EXTCODESIZE | |
| 1869 | ISZERO | |
| 186a | PUSH2 | 0x02ec |
| 186d | JUMPI | |
| 186e | PUSH1 | 0x40 |
| 1870 | MLOAD | |
| 1871 | SWAP1 | |
| 1872 | PUSH4 | 0xaf6f8c1b |
| 1877 | PUSH1 | 0xe0 |
| 1879 | SHL | |
| 187a | DUP3 | |
| 187b | MSTORE | |
| 187c | PUSH1 | 0x04 |
| 187e | DUP3 | |
| 187f | ADD | |
| 1880 | MSTORE | |
| 1881 | PUSH0 | |
| 1882 | DUP2 | |
| 1883 | PUSH1 | 0x24 |
| 1885 | DUP2 | |
| 1886 | DUP4 | |
| 1887 | DUP11 | |
| 1888 | GAS | |
| 1889 | CALL | |
| 188a | DUP1 | |
| 188b | ISZERO | |
| 188c | PUSH2 | 0x0708 |
| 188f | JUMPI | |
| 1890 | PUSH2 | 0x18c1 |
| 1893 | JUMPI | |
| 1894 | JUMPDEST | |
| 1895 | POP | |
| 1896 | PUSH2 | 0x18a0 |
| 1899 | DUP2 | |
| 189a | DUP5 | |
| 189b | DUP5 | |
| 189c | PUSH2 | 0x1eb5 |
| 189f | JUMP | |
| 18a0 | JUMPDEST | |
| 18a1 | CALLDATALOAD | |
| 18a2 | SWAP1 | |
| 18a3 | PUSH1 | 0x01 |
| 18a5 | DUP2 | |
| 18a6 | ADD | |
| 18a7 | SWAP2 | |
| 18a8 | DUP3 | |
| 18a9 | DUP3 | |
| 18aa | GT | |
| 18ab | PUSH2 | 0x0509 |
| 18ae | JUMPI | |
| 18af | PUSH2 | 0x18ba |
| 18b2 | PUSH1 | 0x01 |
| 18b4 | SWAP4 | |
| 18b5 | DUP8 | |
| 18b6 | PUSH2 | 0x1c80 |
| 18b9 | JUMP | |
| 18ba | JUMPDEST | |
| 18bb | MSTORE | |
| 18bc | ADD | |
| 18bd | PUSH2 | 0x16db |
| 18c0 | JUMP | |
| 18c1 | JUMPDEST | |
| 18c2 | PUSH0 | |
| 18c3 | PUSH2 | 0x18cb |
| 18c6 | SWAP2 | |
| 18c7 | PUSH2 | 0x1be1 |
| 18ca | JUMP | |
| 18cb | JUMPDEST | |
| 18cc | DUP12 | |
| 18cd | PUSH2 | 0x1894 |
| 18d0 | JUMP | |
| 18d1 | JUMPDEST | |
| 18d2 | DUP9 | |
| 18d3 | PUSH4 | 0x22566cfd |
| 18d8 | PUSH1 | 0xe0 |
| 18da | SHL | |
| 18db | PUSH0 | |
| 18dc | MSTORE | |
| 18dd | PUSH1 | 0x04 |
| 18df | MSTORE | |
| 18e0 | PUSH1 | 0x24 |
| 18e2 | PUSH0 | |
| 18e3 | REVERT | |
| 18e4 | JUMPDEST | |
| 18e5 | DUP9 | |
| 18e6 | PUSH4 | 0xc9cdeff5 |
| 18eb | PUSH1 | 0xe0 |
| 18ed | SHL | |
| 18ee | PUSH0 | |
| 18ef | MSTORE | |
| 18f0 | PUSH1 | 0x04 |
| 18f2 | MSTORE | |
| 18f3 | PUSH1 | 0x24 |
| 18f5 | PUSH0 | |
| 18f6 | REVERT | |
| 18f7 | JUMPDEST | |
| 18f8 | PUSH1 | 0x20 |
| 18fa | DUP6 | |
| 18fb | PUSH1 | 0x40 |
| 18fd | MLOAD | |
| 18fe | SWAP1 | |
| 18ff | DUP2 | |
| 1900 | MSTORE | |
| 1901 | RETURN | |
| 1902 | JUMPDEST | |
| 1903 | SWAP1 | |
| 1904 | SWAP2 | |
| 1905 | SWAP3 | |
| 1906 | SWAP4 | |
| 1907 | SWAP13 | |
| 1908 | SWAP15 | |
| 1909 | SWAP13 | |
| 190a | PUSH1 | 0x1f |
| 190c | SWAP15 | |
| 190d | SWAP12 | |
| 190e | SWAP15 | |
| 190f | NOT | |
| 1910 | DUP4 | |
| 1911 | DUP3 | |
| 1912 | SUB | |
| 1913 | ADD | |
| 1914 | DUP5 | |
| 1915 | MSTORE | |
| 1916 | PUSH1 | 0x1e |
| 1918 | NOT | |
| 1919 | DUP13 | |
| 191a | CALLDATASIZE | |
| 191b | SUB | |
| 191c | ADD | |
| 191d | DUP6 | |
| 191e | CALLDATALOAD | |
| 191f | SLT | |
| 1920 | ISZERO | |
| 1921 | PUSH2 | 0x02ec |
| 1924 | JUMPI | |
| 1925 | DUP12 | |
| 1926 | DUP6 | |
| 1927 | CALLDATALOAD | |
| 1928 | ADD | |
| 1929 | SWAP1 | |
| 192a | PUSH1 | 0x20 |
| 192c | DUP3 | |
| 192d | CALLDATALOAD | |
| 192e | SWAP3 | |
| 192f | ADD | |
| 1930 | SWAP2 | |
| 1931 | PUSH1 | 0x01 |
| 1933 | PUSH1 | 0x01 |
| 1935 | PUSH1 | 0x40 |
| 1937 | SHL | |
| 1938 | SUB | |
| 1939 | DUP2 | |
| 193a | GT | |
| 193b | PUSH2 | 0x02ec |
| 193e | JUMPI | |
| 193f | DUP1 | |
| 1940 | PUSH1 | 0x05 |
| 1942 | SHL | |
| 1943 | CALLDATASIZE | |
| 1944 | SUB | |
| 1945 | DUP4 | |
| 1946 | SGT | |
| 1947 | PUSH2 | 0x02ec |
| 194a | JUMPI | |
| 194b | PUSH2 | 0x195a |
| 194e | PUSH1 | 0x20 |
| 1950 | SWAP3 | |
| 1951 | DUP4 | |
| 1952 | SWAP3 | |
| 1953 | PUSH1 | 0x01 |
| 1955 | SWAP6 | |
| 1956 | PUSH2 | 0x1e73 |
| 1959 | JUMP | |
| 195a | JUMPDEST | |
| 195b | SWAP7 | |
| 195c | ADD | |
| 195d | SWAP5 | |
| 195e | ADD | |
| 195f | SWAP2 | |
| 1960 | ADD | |
| 1961 | SWAP15 | |
| 1962 | SWAP13 | |
| 1963 | SWAP15 | |
| 1964 | SWAP14 | |
| 1965 | SWAP11 | |
| 1966 | SWAP14 | |
| 1967 | SWAP2 | |
| 1968 | SWAP1 | |
| 1969 | SWAP2 | |
| 196a | PUSH2 | 0x1556 |
| 196d | JUMP | |
| 196e | JUMPDEST | |
| 196f | DUP4 | |
| 1970 | DUP6 | |
| 1971 | PUSH4 | 0x5b2d6423 |
| 1976 | PUSH1 | 0xe1 |
| 1978 | SHL | |
| 1979 | PUSH0 | |
| 197a | MSTORE | |
| 197b | PUSH1 | 0x04 |
| 197d | MSTORE | |
| 197e | PUSH1 | 0x24 |
| 1980 | MSTORE | |
| 1981 | PUSH1 | 0x44 |
| 1983 | PUSH0 | |
| 1984 | REVERT | |
| 1985 | JUMPDEST | |
| 1986 | CALLVALUE | |
| 1987 | PUSH2 | 0x02ec |
| 198a | JUMPI | |
| 198b | PUSH2 | 0x03b5 |
| 198e | PUSH2 | 0x10c6 |
| 1991 | PUSH2 | 0x1999 |
| 1994 | CALLDATASIZE | |
| 1995 | PUSH2 | 0x1ab8 |
| 1998 | JUMP | |
| 1999 | JUMPDEST | |
| 199a | SWAP1 | |
| 199b | PUSH2 | 0x1c94 |
| 199e | JUMP | |
| 199f | JUMPDEST | |
| 19a0 | CALLVALUE | |
| 19a1 | PUSH2 | 0x02ec |