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

feat: add jerigon test workflow #303

Merged
merged 15 commits into from
Jun 26, 2024
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Continuous Integration

on:
push:
branches: [main]
branches: [develop, main]
pull_request:
branches:
- "**"
Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/jerigon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Jerigon Integration

on:
push:
branches: [develop, main]
pull_request:
branches:
- "**"
workflow_dispatch:
branches:
- "**"


env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io

jobs:
test_jerigon_input_proving:
name: Test proof generation with jerigon input
runs-on: zero-ci
timeout-minutes: 40
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Checkout test-jerigon-network sources
uses: actions/checkout@v4
with:
repository: 0xPolygonZero/jerigon-test-network
path: test-jerigon-network

- name: Install nightly toolchain
uses: dtolnay/rust-toolchain@nightly

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up rust cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true

- name: Run jerigon test network with docker compose
run: |
cd test-jerigon-network
docker-compose -f docker-compose.yml up -d
docker logs -f smart-contracts
echo "Jerigon network is up and running, ready for testing"

- name: Rpc test with curl
run: |
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id":83}' localhost:8545
env:
RUST_LOG: info

- name: Run prove blocks in test_only mode
run: |
cd zero_bin/tools
OUTPUT_TO_TERMINAL=true ./prove_rpc.sh 0x2 0x3 http://localhost:8546 jerigon true 0 0 test_only
echo "Proving blocks in test_only mode finished"


- name: Run prove blocks in real mode
run: |
cd zero_bin/tools
rm -rf proofs/* circuits/* ./proofs.json test.out verify.out leader.out
OUTPUT_TO_TERMINAL=true RUN_VERIFICATION=true ./prove_rpc.sh 0x4 0x5 http://localhost:8546 jerigon true
echo "Proving blocks in real mode finished"

- name: Shut down network
run: |
cd test-jerigon-network
docker-compose -f docker-compose.yml down -v



76 changes: 54 additions & 22 deletions zero_bin/tools/prove_rpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ IGNORE_PREVIOUS_PROOFS=$5
BACKOFF=${6:-0}
RETRIES=${7:-0}

# Sometimes we need to override file logging, e.g. in the CI run
OUTPUT_TO_TERMINAL="${OUTPUT_TO_TERMINAL:-false}"
# Only generate proof by default
RUN_VERIFICATION="${RUN_VERIFICATION:-false}"

mkdir -p $PROOF_OUTPUT_DIR

Expand Down Expand Up @@ -87,38 +91,66 @@ fi
if [[ $8 == "test_only" ]]; then
# test only run
echo "Proving blocks ${BLOCK_INTERVAL} in a test_only mode now... (Total: ${TOT_BLOCKS})"
cargo r --release --features test_only --bin leader -- --runtime in-memory --load-strategy on-demand rpc --rpc-type "$NODE_RPC_TYPE" --rpc-url "$NODE_RPC_URL" --block-interval $BLOCK_INTERVAL --proof-output-dir $PROOF_OUTPUT_DIR $PREV_PROOF_EXTRA_ARG --backoff "$BACKOFF" --max-retries "$RETRIES" > $OUT_LOG_PATH 2>&1
if grep -q 'All proof witnesses have been generated successfully.' $OUT_LOG_PATH; then
echo -e "Success - Note this was just a test, not a proof"
# Remove the log on success if we don't want to keep it.
if [ $ALWAYS_WRITE_LOGS -ne 1 ]; then
rm $OUT_LOG_PATH
fi
exit
command='cargo r --release --features test_only --bin leader -- --runtime in-memory --load-strategy on-demand rpc --rpc-type "$NODE_RPC_TYPE" --rpc-url "$NODE_RPC_URL" --block-interval $BLOCK_INTERVAL --proof-output-dir $PROOF_OUTPUT_DIR $PREV_PROOF_EXTRA_ARG --backoff "$BACKOFF" --max-retries "$RETRIES" '
if [ "$OUTPUT_TO_TERMINAL" = true ]; then
eval $command
retVal=$?
echo -e "Proof witness generation finished with result: $retVal"
exit $retVal
else
echo "Failed to create proof witnesses. See ${OUT_LOG_PATH} for more details."
exit 1
eval $command > $OUT_LOG_PATH 2>&1
if grep -q 'All proof witnesses have been generated successfully.' $OUT_LOG_PATH; then
echo -e "Success - Note this was just a test, not a proof"
# Remove the log on success if we don't want to keep it.
if [ $ALWAYS_WRITE_LOGS -ne 1 ]; then
rm $OUT_LOG_PATH
fi
exit
else
echo "Failed to create proof witnesses. See ${OUT_LOG_PATH} for more details."
exit 1
fi
fi
else
# normal run
echo "Proving blocks ${BLOCK_INTERVAL} now... (Total: ${TOT_BLOCKS})"
cargo r --release --bin leader -- --runtime in-memory --load-strategy on-demand rpc --rpc-type "$NODE_RPC_TYPE" --rpc-url "$3" --block-interval $BLOCK_INTERVAL --proof-output-dir $PROOF_OUTPUT_DIR $PREV_PROOF_EXTRA_ARG --backoff "$BACKOFF" --max-retries "$RETRIES" > $OUT_LOG_PATH 2>&1

retVal=$?
if [ $retVal -ne 0 ]; then
# Some error occurred.
echo "Block ${i} errored. See ${OUT_LOG_PATH} for more details."
exit $retVal
command='cargo r --release --bin leader -- --runtime in-memory --load-strategy on-demand rpc --rpc-type "$NODE_RPC_TYPE" --rpc-url "$3" --block-interval $BLOCK_INTERVAL --proof-output-dir $PROOF_OUTPUT_DIR $PREV_PROOF_EXTRA_ARG --backoff "$BACKOFF" --max-retries "$RETRIES" '
if [ "$OUTPUT_TO_TERMINAL" = true ]; then
eval $command
echo -e "Proof generation finished with result: $?"
else
# Remove the log on success if we don't want to keep it.
if [ $ALWAYS_WRITE_LOGS -ne 1 ]; then
rm $OUT_LOG_PATH
eval $command > $OUT_LOG_PATH 2>&1
retVal=$?
if [ $retVal -ne 0 ]; then
# Some error occurred.
echo "Block ${i} errored. See ${OUT_LOG_PATH} for more details."
exit $retVal
else
# Remove the log on success if we don't want to keep it.
if [ $ALWAYS_WRITE_LOGS -ne 1 ]; then
rm $OUT_LOG_PATH
fi
fi
echo "Successfully generated ${TOT_BLOCKS} proofs!"
fi

echo "Successfully generated ${TOT_BLOCKS} proofs!"
fi


# If we're running the verification, we'll do it here.
if [ "$RUN_VERIFICATION" = true ]; then
echo "Running the verification"

proof_file_name=$PROOF_OUTPUT_DIR/b$END_BLOCK.zkproof
echo "Verifying the proof of the latest block in the interval:" $proof_file_name
echo [ > $PROOF_OUTPUT_DIR/proofs.json && cat $proof_file_name >> $PROOF_OUTPUT_DIR/proofs.json && echo ] >> $PROOF_OUTPUT_DIR/proofs.json
cargo r --release --bin verifier -- -f $PROOF_OUTPUT_DIR/proofs.json > $PROOF_OUTPUT_DIR/verify.out 2>&1

if grep -q 'All proofs verified successfully!' $PROOF_OUTPUT_DIR/verify.out; then
echo "All proofs verified successfully!";
else
echo "there was an issue with proof verification";
exit 1
fi
else
echo "Skipping verification..."
fi
Loading