Aleo for Agents is offline at present

blog·2026-11-25·11 min read

Deep Dive: Why Aleo Must Never Build a Block from Already-Committed Certificates

A validator can hold a certificate that is valid, correctly signed, reachable from the next leader, and sorted in the same deterministic order as every peer. The certificate can still be forbidden from the next block.

That was the failure behind snarkOS PR #4778. After a clean restart on v4.13.0, a testnet validator produced a block with 61 certificates. The canonical block at the same height had 30. The first 31 in the validator's block belonged to the previous block; the remaining 30 matched the canonical block.

The leader certificate matched. So did the timestamp and previous block hash. Yet the subdag root differed, which made the whole block differ and forked the restarted validator.

A race let old, committed DAG history cross the boundary into new ledger history without a bad signature or competing leader.

One certificate, two states

AleoBFT uses a Narwhal-style certificate DAG with Bullshark ordering. Validators propose batches, collect signatures into certificates, and make later certificates reference certificates from the prior round. Those references form a causal graph.

Bullshark chooses leader certificates at designated rounds. Once a leader satisfies the commit rule, a validator walks backward through its causal history. The walk finds linked leaders that may have been committed elsewhere, then produces a deterministic order for the eligible certificates. Aleo packages that ordered subdag into a quorum block.

The word "eligible" carries a lot of weight.

A certificate has at least two independent properties:

  • DAG validity: its signatures, author, round, committee context, parent references, and available transmissions pass the BFT rules.
  • Ledger eligibility: the canonical ledger has not already consumed it in an earlier block.

The first property is mostly structural. The second is historical and changes when the ledger advances. A certificate does not become cryptographically invalid after commitment. It becomes unavailable for reuse.

Think of commitment as a one-way ownership transfer. Before commitment, the DAG may offer a certificate to block construction. After commitment, the ledger owns its place in history. Keeping the object in memory or restoring it from storage does not move that boundary backward.

How the race formed

The faulty execution involved two asynchronous activities that normally agree but do not advance as one transaction:

  • BFT receives certificates, updates its local DAG, finds a committable leader, and runs order_dag_with_dfs.
  • Block sync receives a canonical block, checks it, writes it to the ledger, and updates BFT's view of committed certificates.

A simplified timeline looks like this:

text
BFT task                         Block-sync task
--------                         ---------------
DAG contains block H certs
and block H+1 certs

DFS starts from H+1 leader
DFS sees H certs as uncommitted
                                 canonical block H arrives
DFS returns [31 old, 30 new]
                                 ledger commits block H

candidate H+1 uses all 61

The exact interleaving can vary. The invariant failure does not.

order_dag_with_dfs had a local stopping rule based on certificates marked recently committed in the DAG. That rule is useful during normal BFT operation because it prevents a backward traversal from crossing the latest commit boundary. During restart and catch-up, however, the ledger can move while an ordering pass is in flight. A local DAG marker is then a cache of commitment state, not the authority.

That distinction explains the strange block. The DFS order itself was deterministic. Given the same 61-certificate input set, it produced a stable result. The bug was that 31 members of the set were no longer admissible.

Determinism cannot repair a stale domain.

Why the matching header fields fooled nobody

A quorum block commits to its subdag. Changing the certificate set changes the subdag root, even if every other visible choice is unchanged.

We can describe the two candidates as:

text
canonical(H+1) = Block(prev_hash=hash(H), leader=L, subdag_root=R(30 new certs))
restarted(H+1) = Block(prev_hash=hash(H), leader=L, subdag_root=R(31 old + 30 new certs))

Both candidates extend the same parent. Both use leader L. Their timestamps can match because the leader certificate is the same. Yet R(30) cannot equal R(61) unless the root construction is broken, so the block hashes split.

That is a local safety failure with network consequences. Peers reject the validator's block because their canonical history already placed those 31 certificates in block H. The restarted validator has built a different block H+1 from a stale view of what remains uncommitted.

The boundary belongs to the ledger

PR #4778's lesson is sharper than "clear the DAG after sync." Cleanup is housekeeping. Safety needs an authoritative check at the point where a candidate block becomes real.

The ledger exposes certificate membership through a query such as contains_certificate. Block construction should treat that answer as the eligibility boundary. In rough Rust-like pseudocode:

rust
let update = ledger.begin_ledger_update()?;

let ordered = order_dag_with_dfs(leader)?;
let fresh = ordered
    .into_iter()
    .filter(|certificate| !update.contains_certificate(certificate.id())?)
    .collect::<Result<Vec<_>>>()?;

ensure!(fresh.len() == ordered_len, "subdag crossed the committed boundary");
let block = update.prepare_next_quorum_block(fresh, transmissions)?;
update.check_next_block(&block)?;
update.advance_to_next_block(&block)?;

I prefer rejection over silent filtering in the final construction path. Filtering can change the subdag after ordering and can hide a broken handoff between BFT and sync. Rejecting the stale candidate forces BFT to order again against the new ledger tip. The retry should be cheap compared with accepting a fork.

The read must share the ledger update boundary used to prepare and append the block. A check performed before acquiring the update guard still has a time-of-check/time-of-use hole:

text
check certificates -> sync commits block -> build candidate

Holding one ledger update guard across membership checks, preparation, validation, and append gives those operations one coherent ledger view. The older snarkOS block path already used a ledger update handle to serialize writers. The committed-certificate test belongs inside that protected span.

Why local recently_committed state still matters

Ledger membership checks are more expensive than a lookup in the in-memory DAG. Removing the local boundary would also make ordinary graph walks cross history they can reject early.

Keep both layers, but give them different jobs:

  • The DAG's recent-commit index prunes traversal and saves work.
  • The ledger check decides whether the finished subdag may enter the next block.

One is an optimization with useful protocol context. The other is a safety gate.

The ALLOW_LEDGER_ACCESS shape around order_dag_with_dfs hints at the locking problem. Some callers can consult the ledger while traversing; others may already hold locks or run in contexts where ledger access would create lock-order trouble. A compile-time switch can make those call sites explicit, but it does not remove the need for a final check under the block-building guard.

Locking is the hard part here. Grabbing the ledger from arbitrary DFS branches risks deadlock if sync holds a ledger writer and waits for BFT state while BFT holds its DAG lock and waits for the ledger. A clean design snapshots or orders under the DAG lock, releases it, then validates the resulting certificate IDs while holding the ledger update guard. Never hold both broad locks longer than necessary.

Bullshark already implies this rule

Bullshark's commit rule tells validators which leader histories can be ordered. Its safety argument also assumes that causal history is linearized once. Later anchors pull in uncommitted history, not the entire reachable graph forever.

The Narwhal paper says that, after a certificate is committed, validators deterministically order its full uncommitted causal history. "Uncommitted" is not decorative. Without that subtraction, every future leader can reach old certificates and replay prior history.

A recent formal model of DAG-based BFT nonforking makes the state explicit. Block generation takes a leader's causal history, removes the validator's already-committed certificate set, orders what remains, and updates that committed set after appending the block. The model separates the DAG from the blockchain for the same reason this bug demands a ledger-aware boundary: reachability and eligibility are different relations.

Aleo's own consensus audit found related trouble years earlier. The zkSecurity report documented how a traversal must stop at committed anchors and the garbage-collection frontier. It also described an older certificate-identity issue that could make committed history look new. snarkOS fixed that identity problem by making a certificate ID depend on the certified batch rather than a malleable signature selection.

PR #4778 is a different route to a familiar hazard. Certificate identity can be stable and the traversal can be repeatable, yet a stale commitment view still permits replay.

Comparison with chain-first BFT

A chain-first protocol such as HotStuff usually makes the committed prefix visible through a parent QC or locked block. A proposal extends one parent, and the state machine rejects a proposal that does not extend the accepted prefix. The replay boundary is close to the chain structure.

DAG BFT has more room for confusion. A future leader intentionally reaches a large causal history, including certificates that remain locally stored after commitment. Reachability is broad because that helps availability and throughput. Block eligibility must therefore be narrower than graph reachability.

Garbage collection cannot carry the whole burden. GC may retain committed certificates for peer service, restart recovery, metrics, or a bounded recent window. Safety cannot depend on physical deletion happening before the next traversal. Deletion is allowed to lag. Logical commitment is not.

A regression test worth keeping

The right test needs controlled concurrency. A happy-path restart test may run a thousand times without landing in the bad window.

I would build the regression around a barrier injected between DFS ordering and candidate preparation:

  1. Build and commit block H with 31 certificates.
  2. Leave those certificates reachable in the local DAG, then add the 30 certificates for H+1.
  3. Start BFT ordering for H+1 and pause after it captures the oversized 61-certificate subdag.
  4. Let block sync append canonical block H and mark its certificates committed.
  5. Resume block construction and assert that no block is produced from the stale subdag.
  6. Reorder against the updated ledger, then assert that H+1 contains only the canonical 30 certificates and has the expected subdag root.

The test should compare more than height. Check the previous hash, leader certificate ID, certificate count, ordered certificate IDs, subdag root, and final block hash. The old failure is useful because several header fields matched; an assertion on height or leader alone would pass while the node forked.

Fault injection belongs here too. Run the same schedule with the process stopped after the canonical ledger write but before BFT's recent-commit cache update. On restart, rebuild BFT state from storage and prove that ledger membership still blocks the 31 old certificates.

That extends the recovery discipline from Build a Restore-Proven Aleo Node Backup Drill. A restored database is not proven by opening it. The node must respect the restored chain boundary when live consensus resumes.

What developers and agents should enforce

Node developers should write the invariant directly:

text
For every certificate c in candidate block H+1:
    c is valid in the DAG
    AND ledger.contains_certificate(c.id) == false

After append, the second condition flips to true and must never flip back. Tests should model that as a monotonic property, including restart and sync transitions.

Operational agents can detect the symptom before they can diagnose the race. Alert when two blocks at the same height share a previous hash and leader certificate but differ in certificate count or subdag root. A sudden block containing roughly two normal blocks' worth of certificates is especially suspicious. Preserve the node log, block bytes, certificate IDs, ledger height, BFT round, and restart timestamp before automatically wiping state.

Do not repair such a validator by trusting its local height. Compare its block hash and subdag root with at least one known canonical peer. The signer-cache work discussed in Why Aleo Block Sync Should Cache Signers, Not Recompute Them follows the same separation of concerns: cached structural validity never replaces ledger-context validation.

For code review, ask two blunt questions. Which component owns the committed-certificate truth? What lock or snapshot keeps that truth stable until the candidate block is appended?

If the answers are "the DAG cache" and "none," the race is still there.

Aleo needs deterministic DAG ordering. It also needs a ledger-aware subtraction step under a coherent update boundary. The 61-certificate fork showed why both are required: ordering decides where fresh certificates go, while the ledger decides whether they are fresh at all.