Skip to content

Commit

Permalink
Added documentation for compute_shuffled_index.
Browse files Browse the repository at this point in the history
Added correct json input for compute_shuffled_index circuit in example.
Clone test input data if needed.
  • Loading branch information
HristoStaykov committed Mar 12, 2024
1 parent 1dd367e commit 669824a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 33 deletions.
17 changes: 17 additions & 0 deletions vendor/zkllvm-metacraft-circuits/docs/compute_shuffled_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Compute shuffled index documentation.

### *Implementation*
The implementation code of the circuit is under "DendrETH/vendor/zkllvm-metacraft-circuits/src/circuits_impl/".
This code is used in both the compilation as circuit and as executable.

### *Circuit build*
In order to build as circuit, we need an entry point marked with the `[[circuit]]` directive. This is done through a wrapper
that uses the implementation code and resides in "DendrETH/vendor/zkllvm-metacraft-circuits/src/circuits". Since currently the Crypto3
library does not implement computation of sha256 on a byte buffer, we use a header only library for the sha256 computations, which has
negative performance consequences.

### *Executable build + tests*
The implementation code of the circuit is compiled as executable and tested against the input data from
https://github.com/ethereum/consensus-spec-tests.git. The tests reside in "DendrETH/vendor/zkllvm-metacraft-circuits/src/tests/compute_shuffled_index_test/".
For convenience, we have a script that performs all necessary steps to run the test -> "DendrETH/vendor/zkllvm-metacraft-circuits/scripts/compile_and_run_tests.sh".
It is required that docker is installed on the machine that will run the tests.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ cd $SCRIPT_DIR/../docker && docker build -t zcli:latest -f Dockerfile_zcli . &&

cd $CURRENT_DIR

if [ ! -d $SCRIPT_DIR/../../consensus-spec-tests ]
then
git clone git@github.com:ethereum/consensus-spec-tests.git $SCRIPT_DIR/../../consensus-spec-tests
fi

bash ${SCRIPT_DIR}/run.sh --docker compile

bash ${SCRIPT_DIR}/docker_run.sh make test
2 changes: 1 addition & 1 deletion vendor/zkllvm-metacraft-circuits/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ cd $REPO_ROOT/zkllvm-template
COPY_SOURCE_FILES=0
scripts/run.sh $@
cd $SCRIPT_DIR/..
rm -r $REPO_ROOT/zkllvm-template/src
rm -rf $REPO_ROOT/zkllvm-template/src
mv $REPO_ROOT/src~ $REPO_ROOT/zkllvm-template/src
6 changes: 6 additions & 0 deletions vendor/zkllvm-metacraft-circuits/src/circuits/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ add_example(weigh_justification_and_finalization SOURCES weigh_justification_and

add_dependencies(template compute_shuffled_index)
add_dependencies(template weigh_justification_and_finalization)

add_custom_command(TARGET compute_shuffled_index POST_BUILD
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/compute_shuffled_index.json ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS compile_commands.json
VERBATIM ON
)
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
[
{"int": 0},
{"int": 33},
{
"array": [
[
"166209954665300884822717121800188038799",
"144783094885247872016525034474730739405"
],
[
"316532530640111588187217404778232020911",
"26724093998456942932372011149134879307"
],
[
"129016131943024881685044309516733708576",
"301035858936827583230771718648958481107"
],
[
"38435942355081927355841277555582070467",
"236468793428173394040239098346085887776"
],
[
"155672546387712744663901139927960865151",
"130337062174399240196487120660567896561"
]
{"int": 38},
{"int": 101},
{"int": 90},
{"int": 171},
{"int": 88},
{"int": 193},
{"int": 139},
{"int": 102},
{"int": 135},
{"int": 15},
{"int": 80},
{"int": 161},
{"int": 51},
{"int": 23},
{"int": 28},
{"int": 133},
{"int": 217},
{"int": 165},
{"int": 174},
{"int": 157},
{"int": 222},
{"int": 85},
{"int": 192},
{"int": 202},
{"int": 4},
{"int": 148},
{"int": 145},
{"int": 162},
{"int": 127},
{"int": 79},
{"int": 99},
{"int": 231}
]
},
{
"vector": [
"166209954665300884822717121800188038799",
"144783094885247872016525034474730739405"
]
},
{
"vector": [
"24758149039370610683683259915413762872",
"275362252495473570680232529690834658303"
]
}
{"int": 90}
]

0 comments on commit 669824a

Please sign in to comment.