Skip to content

Commit

Permalink
Merge pull request #421 from matter-labs/popzxc/check-dummy-verifier-…
Browse files Browse the repository at this point in the history
…on-ci

Add check for disabled dummy verifier to CI
  • Loading branch information
dvush authored Apr 14, 2020
2 parents 2e6438d + 8d7629b commit 9665199
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 5 deletions.
1 change: 1 addition & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ steps:
- export ZKSYNC_HOME=`pwd`
- export PATH=$ZKSYNC_HOME/bin:$PATH
- export CARGO_HOME=$ZKSYNC_HOME/target/cargo
- zksync dummy-prover ensure-disabled
- zksync circuit-tests
- zksync prover-tests
- zksync db-test
Expand Down
25 changes: 25 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
#
# Pre-commit hook verifying that inappropriate code will not be committed.

# Colors for the terminal output
RED='\033[0;31m'
NC='\033[0m' # No Color

# Check that `rustfmt` rules are not violated.
if ! cargo fmt -- --check; then
echo "${RED}Commit error!${NC}"
echo "Please format the code via 'cargo fmt', cannot commit unformatted code"
exit 1
fi

VERFIER_CONTRACT_FILE="contracts/contracts/Verifier.sol"

# Check if diff for contract contains setting the `DUMMY_VERIFIER` to the true.
if git diff --cached $VERFIER_CONTRACT_FILE | grep -lq 'constant DUMMY_VERIFIER = true'; then
echo "${RED}Commit error!${NC}"
echo "It seems that line 'constant DUMMY_VERIFIER = true' in 'Verifier.sol' is staged to be committed"
echo "Cannot commit the code with enabled DUMMY_VERIFIER"
echo "Please disable the DUMMY_VERIFIER and try to commit changes again"
exit 1
fi
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ zksync dockerhub-push

# Development

## Committing changes

`zksync` uses pre-commit git hooks for basic code integrity checks. Hooks are set up automatically
within the workspace initialization process. These hooks will not allow to commit the code which does
not pass several checks.

Currently the following criteria are checked:

- Code should always be formatted via `cargo fmt`.
- Dummy Prover should not be staged for commit (see below for the explanation).

## Database migrations

-
Expand Down
6 changes: 6 additions & 0 deletions bin/.setup_env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# Setup env itself
if [ -z "$ZKSYNC_ENV" ]
then

Expand Down Expand Up @@ -30,3 +31,8 @@ then

popd > /dev/null
fi

# Setup the git hooks folder.
if ! git config --local core.hooksPath; then
git config --local core.hooksPath $ZKSYNC_HOME/.githooks/
fi
30 changes: 25 additions & 5 deletions bin/dummy-prover
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ NC='\033[0m' # No Color

USAGE='Usage: zksync dummy-prover [-h|--help|run|status|enable|disable]
where:
-h | --help show this message
run run the Dummy Prover (default)
status get the status of the Dummy Prover (enabled/disabled)
enable enables the Dummy Prover support
disable disables the Dummy Prover support'
-h | --help show this message
run run the Dummy Prover (default)
status get the status of the Dummy Prover (enabled/disabled)
enable enables the Dummy Prover support
disable disables the Dummy Prover support
ensure-disabled checks that Dummy Prover is disabled and exits with code 1 otherwise'

if [ -z $ZKSYNC_ENV ];
then
Expand Down Expand Up @@ -72,6 +73,22 @@ function disable_dummy_prover {
exit 0
}

function ensure_dummy_prover_disabled {
# Checks for the `DUMMY_VERIFIER` constant to be `false`.
# This is mandatory e.g. for CI and deploy since we don't want to accidentally obtain
# a dummy verifier deployed.

if f grep -lq 'constant DUMMY_VERIFIER = true' $ZKSYNC_HOME/contracts/contracts/Verifier.sol; then
# Dummy verifier enabled, the restriction is violated.
echo "DUMMY_VERIFIER constant in Verifier.sol is set to 'true', which is not allowed."
echo "Change the DUMMY_VERIFIER constant value to 'false'"
exit 1
else
# Dummy verifier disabled, it's OK.
exit 0
fi
}

case $COMMAND in
run)
run_dummy_prover
Expand All @@ -85,6 +102,9 @@ case $COMMAND in
disable)
disable_dummy_prover
;;
ensure-disabled)
ensure_dummy_prover_disabled
;;
-h | --help)
echo "$USAGE"
exit 0
Expand Down

0 comments on commit 9665199

Please sign in to comment.