-
Clone all submodules
git submodule update --init --recursive --depth 1 -
Install Z3 4.8.10 from https://github.com/Z3Prover/z3/releases/tag/z3-4.8.10
-
Compile the customized K framework. The following commands are tested on Ubuntu 22.04, for other distributions you might need suitable commands to install required packages.
pushd deps/k sudo apt-get install build-essential m4 openjdk-8-jdk libgmp-dev libmpfr-dev pkg-config flex bison libz3-dev maven python3 cmake gcc clang-11 lld-11 llvm-11-tools zlib1g-dev libboost-test-dev libyaml-dev libjemalloc-dev curl -sSL https://get.haskellstack.org/ | sh sed -i 's/-Werror //' llvm-backend/src/main/native/llvm-backend/CMakeLists.txt mvn package popdNOTE: This will take about 20 minutes. Use
mvn package -DskipTeststo skip tests. NOTE: You could also try to use a newer version of K but you would need to add an extra flag--no-backend-hintsfor thescripts.prove_symbolicscript.Finally, add K binaries to
PATH:export PATH=$(realpath deps/k/k-distribution/target/release/k/bin):$PATH
-
Install Python prerequisites (NOTE: Python 3.7+ is required)
python3 -m pip install -r requirements.txt
-
Install Metamath for verification
sudo apt-get install metamath
-
Install RISC0 for ZK in the
risc0-metamath-15directory:cd risc0-metamath-15 cargo install
If you have cargo install'ed in risc0-metamath already, then the following one-liner should work in most cases.
It generathes the proof for the given source file, compresses it and slices into independent proof objects, then runs it in the RISC0 zkVM.
bash ./qed.sh {SEMANTICS_FILEPATH} {SEMANTICS_MODULE} {SRC_FILEPATH} {OUTPUT_FILEPATH} {TARGET_THEOREM} {LOG_FILE}(run from the project root folder)
{TARGET_THEOREM} is the name of the theorem whose hash we are interested in.
The compressed MM proof will be at OUTPUT_FILEPATH, its sliced version in risc0-metamath/OUTPUT_FILEPATH-sliced.
Time measurements will be saved to {LOG_FILE}.
It might happen you need to switch to rust nightly compiler.
Install rustup and then run
rustup install nightly
rustup default nightlyWe will use the transfer.imp program as an example. There are four inputs:
examples/csl23/imp.k: The semantics of IMPIMP: the main K module of IMPexamples/csl23/blockchain/transfer.imp: the transfer programproof-transfer: the folder in which the generated proofs will be placed.
Following these steps to generate and verify the proof for transfer.imp.
-
Generate the proof(s).
python3 -m scripts.prove_symbolic examples/csl23/imp.k IMP examples/csl23/blockchain/transfer.imp --output proof-transferIf you want the proof to be in a single file, add the
--standaloneflag. -
Load the proofs to Metamath
metamath proof-transfer/goal.mm -
Within the Metamath command line
MM>, type the following command to verify the proofsverify proof * -
You'll see that the proofs are verified.
33787128 bytes were read into the source buffer. The source has 16994 statements; 2586 are $a and 8360 are $p. No errors were found. However, proofs were not checked. Type VERIFY PROOF * if you want to check them. MM> verify proof * 0 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% .................................................. All proofs in the database were verified in 10.32 s.
Generated proofs are usually very large. There are two generic techniques how to deal with this.
We can apply a built-in Metamath compression to generated proofs, it often helps. This is done through Metamath CLI as follows:
metamath {PROOF_FILEPATH}
save proof * /compressed
write sourceProofs can also be sliced into multiple smaller proofs for parallelization as follows:
python3 -m scripts.metamath-extract {PROOF_MM_FILE} {OUTPUT_DIR}All proofs in OUTPUT_DIR can be checked as follows:
cd {OUTPUT_DIR}
for f in *; do metamath "read '$f'" "verify proof *" "exit" >> ../log.txt; done;The file log.txt in the parent directory contains all the logs from Metamath verification, including possible errors.
If you want to run with, edit the file risc0-metamath-15/host/Cargo.toml with the following line:
risc0-zkvm = { version = "0.15.2", features = ["cuda"] }examples/csl: Examples for CSLexamples/csl/svm: support vector machine (SVM) examplesexamples/csl/svm5.imp: an SVM with 5 features
examples/csl/multisvm: support vector machine (SVM) examples with multiclass predictionsexamples/csl/multisvm5.imp: a multiclass SVM with 5 features
examples/csl/perceptron: layer perceptron examples with the ReLU activation functionexamples/csl/perceptron.imp: a layer perceptron with 5 features
examples/csl/blockchain: blockchain examplesexamples/csl/blockchain/transfer.imp: the transfer function
The folder mm-benchmarks contains the best proofs we have for benchmarking Current Examples.
This means they are sliced goals and using abbreviation techniques to press the size down.
The script bench.sh will run RISC0 on these examples and save the results in {LOG_FILE}:
bash ./bench.sh {LOG_FILE}(run from the project root folder)