Lucas Rosa Rewrites Midnight’s Compact Compiler in Rust
The Aiken co-creator published a Rust implementation of Midnight’s Compact compiler. Developer Seungheon Oh reported that formally verified optimizations reduced the circuit size parameter from k=17 to k=15 on some scripts.
By SongMarketCap
Updated:
Lucas Rosa announced on November 28 that he had rewritten the compiler for Compact, Midnight’s smart contract language, in Rust and shared the code on GitHub. During the Unpopular Opinion X Space, Micah, who co-created Cardano’s Aiken with Rosa, described the rewrite as a joint effort and said they were still refining several features. Rosa said he used the existing Scheme compiler as a reference for the implementation.
Why the Compiler Matters for Midnight
The compiler connects the rules a developer writes in Compact to the conditions a zero-knowledge proof must satisfy. A contract might allow someone to access a service after proving they hold a valid credential. The developer writes that rule in Compact. The compiler represents it as a cryptographic circuit that defines what the proof must establish. It also generates JavaScript that the application uses to interact with the contract.
A second implementation lets developers compare how two compilers handle the same contract. They can test whether both accept the same source code and whether the resulting circuits enforce the same conditions. A compiler optimization can change how a circuit represents a calculation while preserving the rule the contract enforces. That makes circuit size one way to assess what the rewrite could offer developers.
Early Tests Show Smaller Circuits
On November 29, Oh reported that the Rust implementation had added formally verified optimization passes. A compiler pass transforms code as it moves through the compilation process. Formal verification can establish that a specific transformation preserves the behavior it is designed to preserve. In Oh’s example, the optimized circuit fit into a smaller size category on some scripts.
The parameter k sets the circuit’s row capacity at 2k. A circuit at k=17 has capacity for 131,072 rows. At k=15, that capacity is 32,768 rows, one quarter of the original. These figures describe the capacity needed to fit the circuit. Oh’s post gave no proof generation timings or measurements across a wider set of contracts. A comparison on the same contract and hardware would show whether the smaller circuit reduces the time a user spends waiting for a proof.
What the Rust Implementation Adds
Rosa reported parallel key generation and said the compiler displays both k and the number of rows a circuit uses. He also said he was expanding the project to support a JavaScript and TypeScript SDK with native Node.js add-ons.
In the discussion under his announcement, Rosa described testing features across the entire compiler pipeline. He uses snapshot tests to record what the compiler is expected to produce. A change to generated code or an error message then shows up in the comparison with the saved output, giving contributors a way to review changes as they work on the implementation.
[NEWSBREAK]
What Teams With Live Contracts Need to Verify
Midnight’s installation guide lists Compact 0.36.1, which uses language version 0.28.0, for mainnet. The public sources reviewed leave open which Compact versions the Rust implementation supports and whether it is intended for inclusion in the official toolchain.
An earlier change to the official toolchain illustrates why successful compilation is only part of the test. Compact 0.36.0 moved exclusively to version 3 of ZKIR, the intermediate format used to represent circuits. According to the release notes, recompiling a deployed contract that used version 2 changes its verifier keys. The contract can use the new output after those keys are replaced or the contract is redeployed.
For a team with a live Midnight application, the practical test is to compile an existing contract with the Rust implementation, generate a proof, and check whether it verifies against the deployed contract. That would establish whether the team can use the new output with its existing deployment or needs to update the verifier keys or redeploy the contract.