Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hstaykov/add test for weigh justification and finalization #262

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions vendor/zkllvm-metacraft-circuits/docker/Dockerfile_zcli
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM golang:alpine as build

RUN go install github.com/protolambda/zcli@latest
COPY process_ssz.sh /bin

ENTRYPOINT ["/bin/process_ssz.sh"]
45 changes: 45 additions & 0 deletions vendor/zkllvm-metacraft-circuits/docker/process_ssz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

for v in $(find /DendrETH -iname "*ssz_snappy" | grep "weigh_justification_and_finalization_test")
do
echo $v
rm -f ${v}.json
/go/bin/zcli pretty capella BeaconState ssz_snappy:${v} ${v}.json
slot=$(cat ${v}.json | grep "\"slot\"" | grep -E "^[ ]{2}[\"a-z]{1,}" | awk '/slot/ { gsub(/[",]/,"",$2); print $2}')
sed -i '$ d' ${v}.json
echo "," >> ${v}.json
current_gindex=$(( 303104 + (($slot / 32) * 32) % 8192 ))
previous_gindex=$(( 303104 + ((($slot / 32) * 32) - 32) % 8192 ))
/go/bin/zcli proof capella BeaconState ssz_snappy:${v} --gindices 34 | grep witn | tac | \
awk 'BEGIN{printf("\"slot_proof\": [ ");}{current=prev;prev=$3;if(current != "") printf("\"%s\", ", current)}END{printf("\"%s\" ]", prev)}' >> $v.json;
echo "," >> ${v}.json
/go/bin/zcli proof capella BeaconState ssz_snappy:${v} --gindices 50 | grep witn | tac | \
awk 'BEGIN{printf("\"previous_justified_checkpoint_proof\": [ ");}{current=prev;prev=$3;if(current != "") printf("\"%s\", ", current)}END{printf("\"%s\" ]", prev)}' >> $v.json;
echo "," >> ${v}.json
/go/bin/zcli proof capella BeaconState ssz_snappy:${v} --gindices 51 | grep witn | tac | \
awk 'BEGIN{printf("\"current_justified_checkpoint_proof\": [ ");}{current=prev;prev=$3;if(current != "") printf("\"%s\", ", current)}END{printf("\"%s\" ]", prev)}' >> $v.json;
echo "," >> ${v}.json
/go/bin/zcli proof capella BeaconState ssz_snappy:${v} --gindices 49 | grep witn | tac | \
awk 'BEGIN{printf("\"justification_bits_proof\": [ ");}{current=prev;prev=$3;if(current != "") printf("\"%s\", ", current)}END{printf("\"%s\" ]", prev)}' >> $v.json;
echo "," >> ${v}.json
/go/bin/zcli proof capella BeaconState ssz_snappy:${v} --gindices 52 | grep witn | tac | \
awk 'BEGIN{printf("\"finalized_checkpoint_proof\": [ ");}{current=prev;prev=$3;if(current != "") printf("\"%s\", ", current)}END{printf("\"%s\" ]", prev)}' >> $v.json;
echo "," >> ${v}.json
/go/bin/zcli proof capella BeaconState ssz_snappy:${v} --gindices $current_gindex | grep leaf | \
awk '{printf("\"current_epoch_start_slot_root_in_block_roots\":\"%s\"", $3)}' >> ${v}.json
echo "," >> ${v}.json
/go/bin/zcli proof capella BeaconState ssz_snappy:${v} --gindices $current_gindex | grep witn | tac | \
awk 'BEGIN{printf("\"current_epoch_start_slot_root_in_block_roots_proof\": [ ");}{current=prev;prev=$3;if(current != "") printf("\"%s\", ", current)}END{printf("\"%s\" ]", prev)}' >> $v.json;
echo "," >> ${v}.json
/go/bin/zcli proof capella BeaconState ssz_snappy:${v} --gindices $previous_gindex | grep leaf | \
awk '{printf("\"previous_epoch_start_slot_root_in_block_roots\":\"%s\"", $3)}' >> ${v}.json
echo "," >> ${v}.json
/go/bin/zcli proof capella BeaconState ssz_snappy:${v} --gindices $previous_gindex | grep witn | tac | \
awk 'BEGIN{printf("\"previous_epoch_start_slot_root_in_block_roots_proof\": [ ");}{current=prev;prev=$3;if(current != "") printf("\"%s\", ", current)}END{printf("\"%s\" ]", prev)}' >> $v.json;
echo "," >> ${v}.json
/go/bin/zcli root capella BeaconState ssz_snappy:${v} | awk '{printf("\"beacon_state_root\": \"%s\"", $1)}' >> ${v}.json
echo "" >> ${v}.json
echo "}" >> ${v}.json
done


18 changes: 18 additions & 0 deletions vendor/zkllvm-metacraft-circuits/scripts/compile_and_run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

echo "using nilfoundation/zkllvm-template:${ZKLLVM_VERSION:=0.0.86}"

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
echo "SCRIPT_DIR = " $SCRIPT_DIR

CURRENT_DIR=$(pwd)

echo "CURRENT_DIR = " $CURRENT_DIR

cd $SCRIPT_DIR/../docker && docker build -t zcli:latest -f Dockerfile_zcli . && docker run -v $SCRIPT_DIR/../../:/DendrETH zcli:latest

cd $CURRENT_DIR

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

bash ${SCRIPT_DIR}/docker_run.sh make test
13 changes: 13 additions & 0 deletions vendor/zkllvm-metacraft-circuits/scripts/docker_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

echo "using nilfoundation/zkllvm-template:${ZKLLVM_VERSION:=0.0.86}"

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

docker run --rm -it --name zk_executable_tests \
--volume ${SCRIPT_DIR}/../zkllvm-template/build:/build \
--volume ${SCRIPT_DIR}/../../consensus-spec-tests/:/consensus-spec-tests \
--user $(id -u ${USER}):$(id -g ${USER}) \
-w /build \
ghcr.io/nilfoundation/zkllvm-template:${ZKLLVM_VERSION} \
$@
13 changes: 13 additions & 0 deletions vendor/zkllvm-metacraft-circuits/scripts/format_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
echo "using nilfoundation/zkllvm-template:${ZKLLVM_VERSION:=0.0.86}"

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
CURRENT_DIR=$(pwd)
COMMAND='for v in $(find -iname "*.cpp" -o -iname "*.hpp" -o -iname "*.h" -o -iname "*.c" | grep -v json.hpp); do echo "applying format to" $v; clang-format -i $v; done'

docker run --rm -it --name code_formatter \
--volume ${SCRIPT_DIR}/../src:/src \
--user $(id -u ${USER}):$(id -g ${USER}) \
-w /src \
ghcr.io/nilfoundation/zkllvm-template:${ZKLLVM_VERSION} \
/bin/bash -c "$COMMAND"
94 changes: 94 additions & 0 deletions vendor/zkllvm-metacraft-circuits/src/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
BasedOnStyle: WebKit
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BreakAfterJavaFieldAnnotations: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakStringLiterals: true
ColumnLimit: 120
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
ForEachMacros: ['BOOST_FOREACH']
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^"(<)/'
Priority: 1
- Regex: '^(<(boost)/)'
Priority: 2
- Regex: '^(<(nil\/crypto3)/)'
Priority: 3
- Regex: '.*'
Priority: 4
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: true
Language: Cpp
NamespaceIndentation: All
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 4
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never

...
49 changes: 14 additions & 35 deletions vendor/zkllvm-metacraft-circuits/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
set(CMAKE_BUILD_TYPE "Debug")

add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)

function(add_example example_target)
set(prefix ARG)
set(noValues "")
Expand Down Expand Up @@ -39,43 +44,17 @@ function(add_example example_target)
${Boost_LIBRARIES})
endfunction()

add_custom_target(template)

add_example(compute_shuffled_index SOURCES compute_shuffled_index.cpp INPUT main.inp)

add_executable(compute_shuffled_index_runable compute_shuffled_index_runable.cpp)
cm_find_package(Boost COMPONENTS REQUIRED filesystem)

add_dependencies(template compute_shuffled_index_runable)
add_custom_target(template)

set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
find_package(LLVM REQUIRED CONFIG)

add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

target_link_libraries (compute_shuffled_index_runable
crypto3::algebra
crypto3::block
crypto3::codec
crypto3::containers
crypto3::hash
crypto3::kdf
crypto3::mac
marshalling::core
marshalling::crypto3_algebra
marshalling::crypto3_multiprecision
marshalling::crypto3_zk
crypto3::math
crypto3::modes
crypto3::multiprecision
crypto3::passhash
crypto3::pbkdf
crypto3::threshold
crypto3::pkpad
crypto3::pubkey
crypto3::random
crypto3::stream
crypto3::vdf
crypto3::zk
# enable testing functionality
enable_testing()

${Boost_LIBRARIES})
add_subdirectory(tests)
add_subdirectory(circuits)
82 changes: 0 additions & 82 deletions vendor/zkllvm-metacraft-circuits/src/byte_utils.h

This file was deleted.

Loading
Loading