This repository contains a proof-of-concept Lean infrastructure for verification of SP1 zk chips. It is organised as follows:
Sp1Poc/Wheels.leancontains auxiliary functions on Lean standard types;Sp1Poc/Basic.leancontains basic definitions, functions, and facts about the BabyBear field and conformance theorem templating, noting that the fact that 2013265921 is prime is axiomatised as there are issues with its automated proof on Mac M1-M4 machines;Sp1Poc/Specs.leancontains manually written specifications of chip behaviours---currently, it contains only the specification of wrap-around 32-bit addition;Sp1Poc/Templater.leangenerates the conformance theorem templates;Sp1Poc/Cli.leandefines the command-line arguments for template generation;Sp1Poc.leanbrings the previous modules together to define the mainSp1Pocmodule;Main.leandefines the main user-facing function; andExamples/AddSub.main.leancontains the proof that the constraints extracted from the \texttt{AddSub} chip conform to the specification of wrap-around 32-bit addition, and is elaborated on in detail in \S\ref{sec:proof}.
Assuming that an installation of a version of Lean is present on the system, the infrastructure can be built using the following commands:
lake clean
lake update
lake exe cache get!
lake build
Once the installation has completed, the infrastructure can be used to generate a conformance theorem template by running:
lake exe genTemplate path-to-constraints-file template-folder-name [-f]
where:
path-to-constraints-fileis the path to a file that contains constraints extracted from an SP1 zk chip using the extraction mechanism;- the generated template will be stored in the
Generated/template-folder-name/main.leanfile; -fis an optional argument to denote that generated files should be overwritten if they already exist.