Introduction

This report presents the findings of a security audit conducted on Lighter’s desert exit ZK circuits. The audit was performed by zkSecurity starting November 3rd, 2025, with two consultants over a period of one week. The audit focuses on the emergency withdrawal (escape hatch) mechanism that allows users to withdraw funds when the Sequencer is unavailable, and some minor changes done to other components. This is the 5th audit in a series of audits on the Lighter protocol, so we will give a brief overview focused on the newly reviewed functionality.

Scope

The audit was conducted on commit b99c425b8c0868501e65e78fd16aaf16bbe0ea2b of a private lighter-prover repository. The primary focus was the desert exit circuit located in the desertexit/circuits/ folder. This circuit implements the escape hatch mechanism and consists of:

  • inner_circuit.rs: The core business logic that validates exit claims against the state root, computes total account value (TAV), and verifies withdrawal amounts.
  • outer_circuit.rs: The proof wrapping layer that enables recursive proof verification.
  • pubdata_account.rs / pubdata_market.rs: Data structures representing account and market state extracted from blob data.
  • deserializers.rs: Logic for deserializing blob data into circuit-compatible formats.

In addition to the desert exit circuit, several minor changes to the main transaction circuits were in scope. These include: corrections to zero quote calculation in liquidation and deleverage transactions; exclusion of frozen markets from margin requirements (while still counting unrealized PnL and funding in TAV); modifications to the delta circuit’s sign packing during polynomial evaluation; removal of the health check requirement for deleveragers; transfer restrictions for frozen public pools; and allowing users to set a zero public key.

Two cross-cutting changes were also reviewed: the try_sub_biguint refactor, which now explicitly returns and checks the borrow flag to avoid underflows in disabled constraint branches; and the migration of quote_multiplier from the private market hash to the public hash and blob data, making it available for desert exit TAV calculations.

Overview of Key Concepts

The desert exit mechanism (or Escape Hatch in the Lighter whitepaper) is a functionality of the Lighter L1 contract. It allows users to submit an exit claim and withdraw funds from the contract, even when the Sequencer fails to include transactions.

Circuit. Naturally, any exit claim submitted by a user must be checked for validity against the latest available state root. This verification is performed using a SNARK. The SNARK circuit takes as input a trusted state root and validium root, an untrusted exit claim, and untrusted blob data. It then performs the following verification logic:

  1. assert that the validium and state roots can be reconstructed from the untrusted blob data.
  2. compute the user’s total account value (TAV) from the (now trusted) blob data.
  3. assert that the exit claim is made for valid accounts and matches the computed TAV.

Proof wrappers. The SNARK uses the common pattern of proof wrapping (or proof recursion). The circuit is first proven client-side using a proof system that has good prover performance but larger proofs and verifier times, in this case Plonky2. This produces a first proof that then gets wrapped using a different proof system which has small proofs and cheap on-chain verification. Specifically, the Gnark implementation of Plonk over the BN254 elliptic curve.

We note that in the audited code, the SNARK uses 3 proof system layers (and therefore wraps twice):

  • the first layer is a Plonky2 circuit that does arithmetic over the Goldilocks field. It enforces the business logic listed above. The Merkle trees and verifier challenges for this proof are computed using the Poseidon hash function for the Goldilocks field.
  • the second layer is a Plonky2 circuit that does arithmetic over the Goldilocks field. It verifies the first layer proof against its public inputs. The Merkle trees and verifier challenges for this proof are computed using the Poseidon hash function for the scalar field of the BN254 elliptic curve. This change of hash function allows the proof to be efficiently verified by the next layer.
  • the third and final layer is a Gnark circuit that does arithmetic over the scalar field of the BN254 elliptic curve. It verifies the second layer proof against its public inputs. The resulting proof is much smaller than the hash-based proofs produced by the previous two layers.

TAV calculation. The total account value (TAV) calculation is a central step in the validation of an exit claim since it dictates how much funds can be withdrawn. The desert hatch circuit is hard-coded to support an exit claim on one main account with up to 16 sub-accounts. The circuit assumes that these sub-accounts represent shares in public pools.

The TAV is calculated from the positions of the main account; the TAV of each pool, proportioned by the amount of shares owned in that pool; and the remaining collateral. The withdrawable amount depends directly on the TAV. If the TAV is 0 or negative, then no funds can be withdrawn. If the main account is a public pool, then only the operator fee (see documentation) can be withdrawn; this fee is calculated separately as a function of the pool TAV. Finally, if the TAV is positive and the main account is not a public pool, then the withdrawable amount is exactly the TAV.

We detail the constants, variables and steps that go into the calculation of the TAV and withdrawable amount below. Note that for this exposition we fix a missing variable assignment (as described in our findings).

Summary of the constants, variables and calculation steps towards computing an account's TAV.

The complete formula for the TAV calculation is:

TAVfinal=1M×max(0,TAVraw)×α

where:

  • TAVraw=M×[i=0npos1(vinotional+δifunding)+Cagg]+i=1naccountssi×pool_taviSi.
  • α=1 for regular users and α=sop/Stotal for pool operators.

Note: following the introduction of the spot market functionality, the exit hatch circuit has been modified to support withdrawal of assets other than USDC. We discuss these changes in the corresponding report, “Audit of Lighter’s Spot Market Circuits and Multi-Asset Support”.

Computing the state root. The state root is computed as a hash of hashes: the public market info root, the account tree root and the validium root. Each root is computed as a hash (or hash tree) of some underlying data structure. The specific schema for these data structures may vary.

From a security perspective, the properties of hash functions makes the state root a binding commitment to some (set of) strings. In order to ensure that the state roots bins the protocols to a given state, the schema must be designed such that every string has a unique interpretation for the protocol.

Summary and Recommendations

We found the desert exit circuit to be well-designed and to follow sound architectural principles for emergency withdrawal functionality. Our analysis focused on adversarial scenarios where a malicious user or sequencer might attempt to exploit the escape hatch mechanism, examining both soundness (preventing invalid withdrawals) and completeness (ensuring legitimate withdrawals succeed).

The findings below identify logical issues that warrant attention, particularly the TAV computation vulnerability which could allow withdrawal of funds from accounts with negative balances. The remaining findings are relatively minor and relate to arithmetic safety and input validation.

We recommend strengthening the test coverage for the desert exit functionality. The repository includes an end-to-end test (test_inner_desert_if_witness_exists) and a proving pipeline (prove.sh), for which only one example input scenario is provided. Automated end-to-end tests with diverse scenarios, including corner cases such as zero balances, negative TAV, maximum values, and boundary conditions, would provide stronger confidence on the functional correctness of the desert exit.