nilfoundation / proof-market-toolchain Goto Github PK
View Code? Open in Web Editor NEWA toolchain for interaction with the Proof Market protocol.
Home Page: https://docs.nil.foundation/proof-market
License: MIT License
A toolchain for interaction with the Proof Market protocol.
Home Page: https://docs.nil.foundation/proof-market
License: MIT License
Since multithreaded proof generation is not working yet, we should remove this from documentation, so nobody would try using it.
This is how it was described and how it was supposed to work:
To generate proof using the multithreaded version, execute the following:
cd build
./bin/proof-generator/proof-generator-mt \
--proof_out <output file> \
--circuit_input <statement from Proof Market>
--public_input <public input from Proof Market> \
--smp <number of threads>
----shard0-mem-scale <scale>
Proof computation requires temporary space, always allocated to core0
/shard0
.
The following flags require attention for multithreaded use:
smp
- number of threads.smp
to 16.core0
/shard0
will have access to 1 GB of RAM.shard0-mem-scale
- weighted parameter (weight
) to reserve memory for shard0
.shard0
to have more access to RAM in comparison to others.smp
to 8 and shard0-mem-scale
to 9.We first compute ram_per_shard
variable as follows:
ram_per_shard = TOTAL_RAM / (smp + shard0-mem-scale -1)
= 16 / (8 + 8)
= 1
Which equates to the following:
shard0
RAM =shard0-mem-scale
* ram_per_shard
= 9 GBshard1
.... shard7
= ram_per_shard
= 1 GB/per core = 7 GBYou should tune these two variables for the architecture/circuit for which the proof is generated.
There's also a neat trick that we could recommend:
--smp $(nproc)
--smp $(sysctl -n hw.logicalcpu)
See for example:
https://github.com/NilFoundation/zkllvm/blob/master/.github/workflows/build_linux.yml#L105
https://github.com/NilFoundation/zkllvm/blob/master/.github/workflows/build_macos.yml#L77
Statements have the field isPrivate
, which is false by default. With active development, such as during our workshops, a lot of statements will be pushed to the Proof Market. We should make them private by default and let developers make them public explicitly.
prepare_statement.py --private
prepare_statement.py --public
On the market there's a statement with key 93843771:
{
"_key": "93843771",
"createdOn": 1689098910158,
"description": "description",
"input_description": "input_description",
"isPrivate": false,
"name": "nickvolynkin_example_circuit",
"sender": "nickvolynkin",
"type": "placeholder-zkllvm",
"updatedOn": 1689098910158,
"url": "url"
}
Pushing a proof proposal for this statement:
/proof-market-toolchain# python3 scripts/request_tools.py push --cost 2 --file /opt/zkllvm-template/src/main-input.json --key 93843771
returns the following data:
{
"_key": "93846511",
"statement_key": "93843771",
"cost": 2,
"sender": "nickvolynkin",
"status": "created"
}
It's unclear what the _key
is. Must be the proposal's ID.
Rewrite proof market toolchain logic and make it dependent on zkllvm binaries (zkllvm clang
, assigner
, transpiler
) and proof-producer
binary.
The current docs have a few word choice, punctuation, and style issues. Let's fix them before making significant changes like #63.
./getting-started
directory, add redirects https://docs.gitbook.com/product-tour/git-sync/content-configuration#how-to-create-a-redirectMake branches from the branch https://github.com/nilfoundation/proof-market-toolchain/tree/00-gitbook-docs.
For each chunk of work, open a PR from your branch → 00-gitbook-docs. Make chunks small enough to make 2-3 PRs a day.
Our docs describe working with PMT nicely, but fails to provide a link for that repo on GitHub
These pages definitely should include it:
Right now, the generation_time
parameter is just ignored when you're submitting a proof request or proposal via CLI. It's added to arguments but seems to be never used in the push function: https://github.com/NilFoundation/proof-market-toolchain/blob/master/scripts/request_tools.py
So, we have to remove it for now, and when it's implemented we can restore the corresponding parts of the documentation
Keys were renamed recently, but the short versions were not. It makes CLI harder to understand and remember. What if we rename them accordingly?
https://github.com/NilFoundation/proof-market-toolchain/blob/master/scripts/proof_tools.py
- parser_push.add_argument("-a", "--proposal_key", type=str, default=None, help="proposal_key")
+ parser_push.add_argument("-p", "--proposal_key", type=str, default=None, help="proposal_key")
- parser_push.add_argument("-b", "--request_key", type=str, default=None, help="request_key")
+ parser_push.add_argument("-r", "--request_key", type=str, default=None, help="request_key")
parser_push.add_argument(
"-f", "--file", type=str, required=True, help="file with proof"
)
- parser_get.add_argument("-p", "--proof_key", type=str, help="key of the proof")
+ parser_get.add_argument("-k", "--proof_key", type=str, help="key of the proof")
parser_get.add_argument("-f", "--file", type=str, help="file to write proof")
parser_get.add_argument("-b", "--request_key", type=str, help="request_key")
/proof-market-toolchain$ python3 scripts/auth_tools.py --help
Traceback (most recent call last):
File "/proof-market-toolchain/scripts/auth_tools.py", line 5, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
./scripts/signup.py
, script saves credentials in ./scripts/.user
and ./scripts/.secret
.
./scripts/.user
and ./scripts/.secret
../scripts/auth_tools.py
, script saves JSON web token in ./auth.json
./auth.json
.There's a number of problems here:
docker run -it --rm \
...
--volume $(pwd)/.config/.user:/proof-market-toolchain/scripts/.user \
--volume $(pwd)/.config/.secret:/proof-market-toolchain/scripts/.secret \
--volume $(pwd)/.config/auth.json:/proof-market-toolchain/auth.json \
...
./scripts/signup.py
on in WebUI and saves their credentials elsewhere: in a password manager, in memory, on a sticky note, whatever../scripts/auth_tools.py
, the script prompts for credentials, gets a JSON web token, and saves it in ~/.config/proof-market/auth.json
.Further on and out of scope of this issue, we'll make the following changes:
proof-producer
binary will look for its configuration file somewhere under /etc/proof-market/config.ini
--config
and --auth
parameters.This change refers to the workflow where proof producers get public inputs from the order itself. JSON structuring requires changing as this was not compatible with the proof producer binary.
When I run the proof-generator
with empty input or with -h
and -v
, I get unexpected results:
root@5ffc715e5f63:/proof-market-toolchain# /proof-market-toolchain/build/bin/proof-generator/proof-generator
can not read options configuration file '/root/.config/config.ini'
terminate called after throwing an instance of 'boost::wrapexcept<boost::property_tree::ini_parser::ini_parser_error>'
what(): /root/.config/config.ini: cannot open file
Aborted (core dumped)
root@5ffc715e5f63:/proof-market-toolchain# /proof-market-toolchain/build/bin/proof-generator/proof-generator -v
can not read options configuration file '/root/.config/config.ini'
terminate called after throwing an instance of 'boost::wrapexcept<boost::property_tree::ini_parser::ini_parser_error>'
what(): /root/.config/config.ini: cannot open file
Aborted (core dumped)
# slightly different result, but still an error:
root@5ffc715e5f63:/proof-market-toolchain# /proof-market-toolchain/build/bin/proof-generator/proof-generator -h
Command_Line_Options:
-h [ --help ] Display available command-line
configuration arguments
-c [ --configuration-files ] arg (=/root/.config/config.ini)
Configuration files
NIL Proof Generator:
-v [ --version ] Display version
--proof_out arg Output file
--circuit_input arg Circuit input file
--public_input arg Public params input file
Json circuit description parsing failed: incomplete JSON
Json public_input parsing failed: incomplete JSON
terminate called after throwing an instance of 'boost::wrapexcept<std::invalid_argument>'
what(): not an object
Aborted (core dumped)
root@5ffc715e5f63:/proof-market-toolchain# /proof-market-toolchain/build/bin/proof-generator/proof-generator
can not read options configuration file '/root/.config/config.ini'
terminate called after throwing an instance of 'boost::wrapexcept<boost::property_tree::ini_parser::ini_parser_error>'
what(): /root/.config/config.ini: cannot open file
Aborted (core dumped)
The image is built from commit e7ac895, which is based on master branch commit 9008207
Limit request: {
"_key": "96804968",
"cost": 10,
"sender": "nickvolynkin",
"statement_key": "96079532",
"status": "created"
}
root@3ba82297fb2d:/proof-market-toolchain# python3 scripts/proof_tools.py get --request_key 96804968
Traceback (most recent call last):
File "/proof-market-toolchain/scripts/proof_tools.py", line 89, in <module>
args.func(args=args)
File "/proof-market-toolchain/scripts/proof_tools.py", line 66, in get_parser
get(args.auth, args.request_key, args.proof_key, args.file)
File "/proof-market-toolchain/scripts/proof_tools.py", line 52, in get
res_json = res.json()[0]
IndexError: list index out of range
Running sh ./build.sh in docker cause the following errors:
CMake Warning (dev) in CMakeLists.txt: No project() command is present. The top-level CMakeLists.txt file must contain a literal, direct call to the project() command. Add a line of code such as project(ProjectName) near the top of the file, but after cmake_minimum_required(). CMake is pretending there is a "project(Project)" command on the first line. This warning is for project developers. Use -Wno-dev to suppress it. CMake Error at CMakeLists.txt:26 (include): include could not find requested file: CMConfig CMake Error at CMakeLists.txt:27 (include): include could not find requested file: CMDeploy CMake Error at CMakeLists.txt:28 (include): include could not find requested file: CMSetupVersion CMake Error at CMakeLists.txt:30 (cm_workspace): Unknown CMake command "cm_workspace".
Publish ready-to-work docker image:
Currently, users have to compile the project themselves, which takes a lot of time and reduces the success rate.
This image will help new users start working with Proof Market in several minutes.
Also, we will use this image in CI for checking integration between zkLLVM and Proof Market.
Image names:
# build-base image: all dependencies, but no compiled code
ghcr.io/nilfoundation/proof-market-toolchain:base
# ready-to-use image: all dependencies + compiled toolchain applications
ghcr.io/nilfoundation/proof-market-toolchain:latest
Local verifier is required for many cases, so it makes sense to implement it standalone form similar to the proof-producer (https://github.com/NilFoundation/proof-producer).
Add ccache to the build image. Build proof market in it once from the main branch, and save the cache in the image.
As a result, when folks build the proof market in a container, the build will be blazing fast.
Blocked by #35
Current docker build requires users to run/build it locally. This task is to track publishing it to the docker repository.
It seems that proof-market toolchain would be more convenient to use if the user could easily substitute the proof-producer binaries.
Because many teams will inevitably do custom implementations and optimizations of our prover (including hardware-specific deployments), it may make sense to give them a separate repository, which they could fork and do their job there.
Separate prover can be moved to https://github.com/NilFoundation/proof-producer
Check this issue after proof-producer is separated: NilFoundation/zkLLVM#178
The image built from ./scripts/proof_producer/build_scripts/Dockerfile
can use ghcr.io/nilfoundation/proof-market-toolchain:base
, built from ./Dockerfile.base
. It will improve the build speed, mainly because it skips Boost compilation.
Things to do and check:
ubuntu:22.04
requests==2.28.2
dependency manually installed in the dev-mode Dockerfile, and one in ./requirements.txt
. Let's bring it to consistency and use one source.Follow-up to #36
Follow-up to #49
Pages that should be updated:
Right now we have some structural choices, like folders guides/
and guides-1/
, repeating parts and not-so-obvious namings like Terminology, when it's more like Market mechanics. I suggest we update it and make the documentation more structured
https://www.notion.so/nilfoundation/nil-developer-hub-website-f87a3511a04b457b894c16ee7f3d5223?pvs=4#e251cea1ca9a45aebbb54417f041c86a
statement_tools returns statements as a raw JSON output. There should be a way to see a neat table, like with docker image ls
or
python3 scripts/statement_tools.py get
KEY DESCRIPTION AVG_COST AVG_TIME URL
79169223 Account state proof for Mina 6.32 8.8s https://github.com/NilFoundation/mina-state-proof
32292 mina state proof 6.42 9835s https://github.com/NilFoundation/mina-state-proof
There's no need to go all the way with dependencies in the container-based workflow.
Test File: charcpp_test.cpp
#include <cstddef>
[[circuit]] size_t strlen(const char *str) {
size_t counter = 0;
while (str[counter++] != '\0');
return counter - 1;
}
Input File: charcpp_input.json
{
"input": "abcdefgh"
}
/home/robertorosmaninho/rv/zk-experiments/zkllvm/build/libs/circifier/llvm/bin/clang-16 -target assigner -Xclang -no-opaque-pointers -Xclang -fpreserve-vec3-type -std=c++20 -D__ZKLLVM__ -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/algebra/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/build/include -I /home/robertorosmaninho/rv/boost_1_76_0/build/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/block/include -I /home/robertorosmaninho/rv/boost_1_76_0/build/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/blueprint/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/codec/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/containers/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/hash/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/kdf/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/mac/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/marshalling/core/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/marshalling/algebra/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/marshalling/multiprecision/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/marshalling/zk/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/math/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/modes/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/multiprecision/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/passhash/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/pbkdf/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/pkmodes/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/pkpad/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/pubkey/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/random/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/stream/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/vdf/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/crypto3/zk/include -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/stdlib/libcpp -I /home/robertorosmaninho/rv/zk-experiments/zkllvm/libs/stdlib/libc/include -emit-llvm -O1 -S charcpp_test.cpp
python ./scripts/prepare_statement.py -c=charcpp_test.ll -o=test_statement.json -n=test -t=placeholder-zkllvm
./build/bin/proof-generator/proof-generator --proof_out=test_output.bin --circuit_input=test_statement.json --public_input=charcpp_input.json
proof-generator
:terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
generatring zkllvm proof...
Proof is verified
clang version 16.0.0 (https://github.com/NilFoundation/zkllvm-circifier.git 9e73aecf0f3db71cb1fb433f65d56a63654afd1a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/robertorosmaninho/rv/zk-experiments/zkllvm/build/libs/circifier/llvm/bin
$> git log
commit 992025ddbf89a4dbd0c7c1512b25704846577daf (HEAD -> master, tag: v0.0.30, origin/master, origin/HEAD)
$> l
total 16K
drwxrwxr-x 4 robertorosmaninho robertorosmaninho 4.0K May 30 13:27 .
drwxrwxr-x 7 robertorosmaninho robertorosmaninho 4.0K Jun 15 16:20 ..
drwxrwxr-x 3 robertorosmaninho robertorosmaninho 4.0K Jun 15 16:25 proof-generator
I couldn't find a way to output the current version, so I just used git log
and l
.
We don't have documentation for registering as a proof producer.
Pages that should be updated:
$ python3 scripts/bid_tools.py get --key=84304538
Limit bid: {
"_key": "84304538",
"cost": 7,
"sender": "robertogomes",
"statement_key": "79169223",
"status": "completed"
}
Currently proof-key is not returned in the response and we should add this to prevent users from using the -v
flag.
This is a recurring task for updating toolchain when the dependencies are updated.
Pushed a proposal, providing a request ID instead of a statement ID by mistake. (I've formatted the JSON output):
root@61db058b84db:/proof-market-toolchain# python3 scripts/proposal_tools.py push --key 93846511 --cost 2
Limit proposal:
{
'_key': '93849751',
'_id': 'proposal/93849751',
'_rev': '_gSXAKnm---',
'statement_key': '93846511',
'cost': 2,
'sender': 'nickvolynkin',
'wait_period': None,
'eval_time': None,
'createdOn': 1689100890776,
'updatedOn': 1689100890776,
'status': 'created'
}
As you can see, it has status=created
. This request must return an error because there is no statement with this id.
Trying to find my proposal right after pushing it:
root@61db058b84db:/proof-market-toolchain# python3 scripts/proposal_tools.py get --key 93846511
Error: 204
93846511
is in fact a request for statement 93843771
:
root@61db058b84db:/proof-market-toolchain# python3 scripts/request_tools.py get --key 93846511
Limit request: {
"_key": "93846511",
"cost": 2,
"sender": "nickvolynkin",
"statement_key": "93843771",
"status": "created"
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.