How our Quint spec caught a timing bug in zeronym


Our Quint spec of zeronym found a timing bug in its hub that our tests had missed, and we fixed it in #85.
zeronym hides the link between a wallet and its sensitive transactions (ones whose amounts are public) from node operators. A shim in front of the operator’s indexer intercepts these transactions and diverts them to a hub, which broadcasts them in batches. Shim and hub run in TEEs (trusted hardware enclaves the operator cannot read or change), and zeronym is designed so the operator cannot link a wallet to its transaction. We wrote the spec to check protocol guarantees.


For example, a wallet’s transaction could expire while the hub holds it. So the hub guarantees that it broadcasts a supported wallet’s transaction with enough time left for it to be mined. We wrote this as an invariant in Quint, and the model checker broke it in a case we expected to be safe. TLC, a model checker that visits every reachable state, found a 19-state trace in seconds. We followed the trace into the Rust, reproduced it there, found its root cause, and fixed it in #85. This post retraces those steps.
How the hub works
Schedule
The hub queues the transactions it receives (which the spec calls migrations, after the Orchard to Ironwood migration they protect) and broadcasts the whole queue every 20 blocks. A supported wallet’s transaction fits that schedule with room to spare.


- Each broadcast is a flush, and it fires at a flush boundary every 20 blocks.
- The 20 blocks between two boundaries are an epoch.
- A flush offers every queued transaction to the network. If a broadcast fails in a way that can be retried, the hub requeues the transaction for the next flush.
- The first offer is the first time a transaction is broadcast since the hub last started.
- The hub only accepts a transaction if 4 blocks will be left at the next flush boundary. This is the admission rule. The 4-block margin is the mining margin, i.e. the time a node needs to mine it.
Two heights
The hub learns the chain’s height, the observed tip, from its indexer. After 15 minutes with no new tip, the tip is considered stale, and the flush loop runs on a free-running timer instead. The timer starts from the last tip and adds one block for every 75 seconds since that tip arrived. The height the loop runs on is its cadence height.


In practice, blocks don’t arrive exactly every 75 seconds, so the timer could drift from the chain. When blocks are slower, it runs ahead.
From threat to invariant
The threat from the start of the post is T5.
A supported wallet’s migration expires while the hub holds it.
Guarantee G6b answers it.
A supported wallet’s transaction is offered with the mining margin to spare, the first time a hub offers it.
In Quint, G6b becomes the invariant conformingFirstOfferBeforeExpiry, and it reads almost like the English.
val conformingFirstOfferBeforeExpiry =
h.inFlight().forall(payload =>
isConformingAndOnTime(payload) and isFirstOffer(payload) implies marginLeft(payload, flightStart))
This way we tie each threat to guarantees, and each guarantee to an invariant the model checker tries to break. In this case, the invariant checks that for every transaction in a flush, if a supported wallet sent it on time, and this is its first offer, it still has its mining margin when the flush begins.


Writing the spec
Defining the universe
A specification that is too abstract will miss real attacks; one that is too concrete becomes intractable for verification.
Before we wrote any Quint, we wrote down the universe the spec lives in. The spec README defines it in detail.
- The system covers who the actors are and what each one does (e.g. the hub and the chain with its indexer, which supplies the tip and a verdict on each broadcast).
- The assumptions say what must be true of the universe for any claims made against it to apply (e.g. an included transaction is never reorged out, and time is counted in blocks).
- The scope says what the specification deliberately does not cover, and why (e.g. multiple hubs are not modelled for the sake of simplicity).
Inside this universe the model checker can try everything. So there is a tradeoff between spec complexity and exhaustiveness. A bigger universe means more states and slower exhaustive checks, while a smaller one is faster to check but can miss real bugs.
Two specs
We work around this tradeoff by defining two specs, a protocol spec and a hub spec.


The protocol spec has every actor but its hub is abstract (basically a queue that can flush at any time). Random simulation and scripted runs check this spec.
The hub spec models one hub concretely along with the chain, and the two things the hub asks its indexer for, the tip and a verdict on each broadcast. It owns everything the abstract hub leaves out, which is the schedule, expiry, requeue, crash and drain. TLC visits every reachable state of each of its configurations.
An abstraction test (abstractionTest) checks that every reachable real hub step is an abstract hub step. So every invariant of the abstract hub holds on the real hub too.
G6b is about the schedule and expiry, so it lives in the hub spec, where TLC checks it exhaustively.
Drafting the spec
We started with quint-llm-kit, which generated a first draft of the spec from the Rust. We then checked the draft against the code and refined it one component at a time.
Each component is one pure function from its state and an input to its next state and an output. For the mixnet we used the message soup pattern, where a sent message stays in the soup forever, and delivering it leaves it there. The pattern gives us loss, duplication, delay and reordering for free. A Byzantine actor has a set of transitions that contains the honest ones, and the model checker may pick any of them.
Finding a violation
We ran TLC on conformingFirstOfferBeforeExpiry expecting the expiry floor to block every path to a violation, since it leaves room for a tip silence. But TLC found a counterexample with 19 states.
TLC ran on a small schedule (a flush every 3 blocks instead of 20) so it could finish. To make it easier to follow, here is the same trace at the shipped numbers, which we replayed against the spec.


The trace shows a flush the hub spent early because its timer ran ahead of the chain while its tip was stale. Right after the tip comes back, the hub admits a transaction, expecting it to go out in the next flush. But that flush already happened, so the transaction waits for the one after, and it might expire before that batch is mined. That’s a bug. The hub should never have admitted the transaction against a flush it had already spent.
Finding the bug and its root cause in Rust
We reproduced the bug in the Rust hub as the test a_free_running_flush_spends_its_epoch_for_admission_not_for_requeue, which expects the hub to refuse a transaction that counts on a spent flush, and sure enough the test failed. The failure pointed at two places, where the hub records a flush and the height admission judges against.
The flush loop records the epoch from the cadence height. While the tip is stale, that height is the free-running timer.
// hub/src/batcher.rs, before #85
let epoch = tip.cadence_height() / params.flush_interval.max(1);
match last_flush_epoch {
None => last_flush_epoch = Some(epoch),
Some(previous) if epoch > previous => {
flush(&queue, &chain, &tip, params).await;
last_flush_epoch = Some(epoch);
}
// ...
}
Admission works out the next flush from the observed height, and it never sees last_flush_epoch.
// hub/src/server.rs, before #85
match self.queue.admit(
tx_bytes,
self.tip.observed_height(),
self.params.flush_interval,
self.params.mining_margin,
) {
Root cause. The hub kept two records of one schedule. The loop judged by its timer and spent a flush. Admission judged by the observed tip and never saw
last_flush_epoch, so it still counted on that flush.
Fixing the root cause and verifying the fix
#85 gives the hub one record. The tip tracker now holds the boundary of the last flush the loop recorded, and admission judges at the higher of that boundary and the observed tip.
// hub/src/batcher.rs
pub fn admission_height(&self) -> u32 {
let state = self.read();
match state.last_flush_boundary {
None => state.height,
Some(boundary) => state.height.max(boundary),
}
}
Admission must guarantee that an entry it accepts survives the next flush the loop has not spent. In the spec this is G8 (admissionMatchesCadence).
val admissionMatchesCadence =
match h.lastEpoch {
| Some(epoch) =>
h.queued().forall(payload =>
h.queue.get(payload) == 0 implies
survivesNextFlush(payload.expiry, epoch * cfg.params.flushInterval,
cfg.params.flushInterval, cfg.params.miningMargin))
| None => true
}
Every queued entry that has not been requeued (zero attempts) survives the first flush after the last recorded epoch, with the mining margin to spare. We modelled the fixed admission rule in the hub spec, and TLC checks G8 over every reachable state of three configurations. The Rust test now passes.
Limitations
- The bounds are small. TLC and the abstraction test are exhaustive only for small parameters, meaning two or three transactions and low heights. A bug that needs more would go unseen.
- Privacy is checked at the protocol level.
G1checks that the shim forwards to the operator only the transactions its classifier lets through. Every message in the model carries exactly its typed fields, so sizes, timing and other covert channels are a separate question. We are discussing how to model them on the Quint Telegram channel. - The protocol spec is sampled. It is too large for TLC to finish, so its guarantees rest on random simulation of 2,000 traces of up to 40 steps. Any trace the samples didn’t hit is still unchecked.
Future work
Two things would strengthen these results.
- Model-based testing. quint-connect can generate traces from the spec and replay them against the Rust. The spec is shaped for it, because each step gives one input to one component function, and each function maps onto a seam in the code, such as
Hub::admitorTipTracker::observe. What remains is the driver code on the Rust side. - Apalache. The compiled spec is too large for the Apalache server today. A subset small enough to load would give bounded symbolic checking of the protocol guarantees that now rest on simulation.
If you build on Zcash, read the spec and tell us what we missed. If you’re designing a protocol of your own, give Quint a try. It found a bug in ours that our tests had missed.
If you need help with your Zcash infrastructure, contact Shielded Labs.
Thanks to Gabriela Moreira for reviewing the spec and the Quint parts of this post, and for her input on modelling privacy in Quint. Thanks to Mark Henderson, Aayush Giri and Jason McGee for reviewing this post and for their feedback. Mark also contributed to the spec and reviewed bug fixes. Thanks to Zooko Wilcox for feedback on the spec and for the architecture diagram.
References
- Quint, Modeling the Faerie-Gold Vulnerability
- Quint, Message Soup: the Secret Sauce for Consensus Specifications
- quint-llm-kit and quint-connect
- Leslie Lamport, Paxos.tla

