An educational tiny STARK protocol engine in Java 21.
This repository contains reusable protocol pieces plus a small example
statement. The example proves a public square relation, f = x * x, while the
generic protocol code stays independent of that specific computation.
The implementation is small on purpose, with commented source code that follows the main STARK layers: field arithmetic, polynomial interpolation, trace commitments, AIR composition, Fiat-Shamir, Merkle openings, toy FRI, proof serialization, and a generic protocol API.
This is not production cryptography. It is a learning implementation designed to make the protocol shape visible.
The reusable educational protocol is implemented end to end:
- Goldilocks prime field arithmetic
- polynomial operations and Lagrange interpolation
- power-of-two evaluation domains
- expression-based AIR definitions
- generic composition construction for expression-based AIR
- generic proof object, prover, verifier, and codec
- example package proving
f = x * x - trace low-degree-extension commitment
- SHA-256 Merkle commitments and openings
- Fiat-Shamir transcript
- sampled trace and composition query checks
- toy FRI folding checks for the composition codeword
- deterministic proof binary codec
Run tests:
./mvnw -q testCompile:
./mvnw -q compileCreate and verify a square proof:
java -cp target/classes io.tinystark.cli.TinyStarkCli prove-square 7 square.proof
java -cp target/classes io.tinystark.cli.TinyStarkCli verify-square square.proofsrc/main/java/io/tinystark/
- air/ generic AIR interface and expression-based AIR constraints
- cli/ minimal command-line entry point
- commitment/ SHA-256 Merkle tree and Merkle proofs
- composition/ generic composition quotient polynomials
- domain/ power-of-two evaluation domains
- example/ concrete example statements built on the generic protocol
- field/ Goldilocks field implementation
- fri/ toy FRI prover, verifier, proof objects
- polynomial/ polynomial arithmetic and interpolation
- protocol/ generic STARK protocol, proof objects, prover, verifier, and codec
- trace/ trace table
- transcript/ Fiat-Shamir transcript
Detailed theory and protocol notes:
Small statements can be written as AIR formulas instead of custom composition code. A statement should provide:
- a trace generator
- a
ProgramAirbuilt from expression constraints - public input labels and values
- optional CLI glue if it should be runnable from the command line
The reusable protocol entry points are:
StarkProver.prove(StarkStatement)StarkVerifier.verify(StarkProof, ProgramAir)StarkProofCodec.encode(...)StarkProofCodec.decode(...)
See io.tinystark.example.SquareStatement for the smallest concrete example.
It builds a two-column trace where column 0 is x, column 1 is f, and the AIR
constraint enforces f - x*x = 0.
At a high level, the generic prover:
- Receives a
StarkStatement. - Checks that the witness trace satisfies the AIR.
- Interpolates trace columns over the execution domain.
- Evaluates the trace low-degree extension over the larger composition domain.
- Commits to trace LDE rows with a Merkle tree.
- Samples random composition challenges from the transcript.
- Builds the composition polynomial by dividing AIR numerators by their zerofiers.
- Commits to the composition codeword.
- Commits to FRI folded codewords.
- Samples query indices after all commitments are transcript-bound.
- Opens trace rows, shifted trace rows, composition values, and FRI paths.
- Returns a deterministic proof object.
The generic verifier:
- Replays public inputs into the Fiat-Shamir transcript.
- Recomputes composition challenges from the trace root.
- Replays composition and FRI roots into the transcript.
- Recomputes query indices.
- Verifies Merkle openings for trace LDE rows and composition values.
- Recomputes composition values from opened trace values and AIR constraints.
- Verifies toy FRI folding paths and the final constant layer.
This project is useful for learning the shape of a STARK, but it intentionally leaves out many production requirements:
- no security parameter calibration
- no optimized FFT/NTT implementation
- no grinding or proof-of-work against transcript bias
- no domain separation audit beyond simple labels
- no constant-time side-channel review
- no production-grade FRI batching or DEEP-FRI
- only a small expression-based AIR builder, not a complete AIR language
- no formal soundness analysis for chosen parameters
Treat it as a readable tiny STARK, not as a secure proving system.
The repository still contains a minimal Spring Boot application generated at the start of the project. The STARK protocol does not depend on the web endpoint; the library packages are the main implementation.