diff --git a/.githooks/pre-push b/.githooks/pre-push index 73168e08ec42..ef5e77cbc796 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -6,14 +6,29 @@ RED='\033[0;31m' NC='\033[0m' # No Color +# Common prompts +INSTALL_PROPT="Please install ZK Stack CLI using zkstackup from https://github.com/matter-labs/zksync-era/tree/main/zkstack_cli/zkstackup" +FORMAT_PROMPT="Please format the code via 'zkstack dev fmt', cannot push unformatted code" + # Check that prettier formatting rules are not violated. -if which zk_supervisor >/dev/null; then - if ! zk_supervisor fmt --check; then +if which zkstack >/dev/null; then + if ! zkstack dev fmt --check; then echo -e "${RED}Push error!${NC}" - echo "Please format the code via 'zks fmt', cannot push unformatted code" + echo -e "${FORMAT_PROMPT}" exit 1 fi else - echo "Please install zk_toolbox using zkup from https://github.com/matter-labs/zksync-era/tree/main/zk_toolbox/zkup, and then run ./bin/zkt from the zksync-era repository." - exit 1 + if which zk_supervisor >/dev/null; then + echo -e "${RED}WARNING: zkup, zk_inception/zki, and zk_supervisor/zks are DEPRECATED.${NC}" + echo -e "${RED}${INSTALL_PROPT}${NC}" + + if ! zk_supervisor fmt --check; then + echo -e "${RED}Push error!${NC}" + echo -e "${FORMAT_PROMPT}" + exit 1 + fi + else + echo -e "${INSTALL_PROPT}" + exit 1 + fi fi diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a712db9f75b4..d68b45e9d435 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -17,4 +17,4 @@ - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. -- [ ] Code has been formatted via `zk_supervisor fmt` and `zk_supervisor lint`. +- [ ] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`. diff --git a/.github/release-please/config.json b/.github/release-please/config.json index 86839e804ca4..358e249a18bd 100644 --- a/.github/release-please/config.json +++ b/.github/release-please/config.json @@ -20,9 +20,9 @@ "release-type": "simple", "component": "prover" }, - "zk_toolbox": { + "zkstack_cli": { "release-type": "simple", - "component": "zk_toolbox", + "component": "zkstack_cli", "plugins": [ "cargo-workspace" ] diff --git a/.github/release-please/manifest.json b/.github/release-please/manifest.json index e0e8fbeecf74..ca19e91219d9 100644 --- a/.github/release-please/manifest.json +++ b/.github/release-please/manifest.json @@ -1,5 +1,5 @@ { "core": "24.28.0", "prover": "16.5.0", - "zk_toolbox": "0.1.2" + "zkstack_cli": "0.1.2" } diff --git a/.github/workflows/build-contract-verifier-template.yml b/.github/workflows/build-contract-verifier-template.yml index bb385b2797b2..e4d04b90410e 100644 --- a/.github/workflows/build-contract-verifier-template.yml +++ b/.github/workflows/build-contract-verifier-template.yml @@ -113,15 +113,19 @@ jobs: ci_run git config --global --add safe.directory /usr/src/zksync/sdk/binaryen ci_run git config --global --add safe.directory /usr/src/zksync/contracts/system-contracts ci_run git config --global --add safe.directory /usr/src/zksync/contracts - ci_run ./bin/zkt || true ci_run ./bin/zk || true ci_run run_retried curl -LO https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2\^26.key + - name: install zkstack + run: | + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup || true + ci_run zkstackup -g --local + - name: build contracts if: env.BUILD_CONTRACTS == 'true' run: | ci_run cp etc/tokens/{test,localhost}.json - ci_run zk_supervisor contracts + ci_run zkstack dev contracts - name: Login to Docker registries if: ${{ inputs.action == 'push' }} diff --git a/.github/workflows/build-core-template.yml b/.github/workflows/build-core-template.yml index 2eb97a001bc1..10741c2ac5af 100644 --- a/.github/workflows/build-core-template.yml +++ b/.github/workflows/build-core-template.yml @@ -129,14 +129,18 @@ jobs: ci_run git config --global --add safe.directory /usr/src/zksync/contracts/system-contracts ci_run git config --global --add safe.directory /usr/src/zksync/contracts ci_run ./bin/zk || true - ci_run ./bin/zkt || true ci_run run_retried curl -LO https://storage.googleapis.com/matterlabs-setup-keys-us/setup-keys/setup_2\^26.key + + - name: Install zkstack + run: | + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup || true + ci_run zkstackup -g --local - name: build contracts if: env.BUILD_CONTRACTS == 'true' run: | ci_run cp etc/tokens/{test,localhost}.json - ci_run zk_supervisor contracts + ci_run zkstack dev contracts - name: Login to Docker registries if: ${{ inputs.action == 'push' }} diff --git a/.github/workflows/build-local-node-docker.yml b/.github/workflows/build-local-node-docker.yml index f664bfaaa00a..80142cb6005c 100644 --- a/.github/workflows/build-local-node-docker.yml +++ b/.github/workflows/build-local-node-docker.yml @@ -53,6 +53,11 @@ jobs: mkdir -p ./volumes/postgres run_retried docker compose pull zk postgres docker compose up -d zk postgres + + - name: Install zkstack + run: | + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup || true + ci_run zkstackup -g - name: init run: | @@ -61,9 +66,11 @@ jobs: ci_run git config --global --add safe.directory /usr/src/zksync/contracts ci_run zk - ci_run zkt ci_run cp etc/tokens/{test,localhost}.json - ci_run zk_supervisor contracts + + - name: build contracts + run: | + ci_run zkstack dev contracts - name: update-image run: | diff --git a/.github/workflows/ci-common-reusable.yml b/.github/workflows/ci-common-reusable.yml index 2f51229aeaf9..7d75fb224d6e 100644 --- a/.github/workflows/ci-common-reusable.yml +++ b/.github/workflows/ci-common-reusable.yml @@ -29,13 +29,14 @@ jobs: run_retried docker-compose -f ${RUNNER_COMPOSE_FILE} pull mkdir -p ./volumes/postgres docker-compose -f ${RUNNER_COMPOSE_FILE} up --build -d zk postgres - - - name: Init + + - name: Install zkstack run: | - ci_run zkt + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup + ci_run zkstackup -g --local # This does both linting and "building". We're using `zk lint prover` as it's common practice within our repo # `zk lint prover` = cargo clippy, which does cargo check behind the scenes, which is a lightweight version of cargo build - name: Lints - run: ci_run zk_supervisor lint -t rs --check + run: ci_run zkstack dev lint -t rs --check diff --git a/.github/workflows/ci-core-lint-reusable.yml b/.github/workflows/ci-core-lint-reusable.yml index 6d0785fe46f1..53b25835ff57 100644 --- a/.github/workflows/ci-core-lint-reusable.yml +++ b/.github/workflows/ci-core-lint-reusable.yml @@ -26,24 +26,30 @@ jobs: - name: Start services run: | ci_localnet_up + + - name: Install zkstack + run: | + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup + ci_run zkstackup -g --local - name: Build run: | - ci_run ./bin/zkt ci_run yarn install ci_run git config --global --add safe.directory /usr/src/zksync - ci_run zk_supervisor db setup --prover-url=${{ env.prover_url }} --core-url=${{ env.core_url }} + - name: Database setup + run: | + ci_run zkstack dev db setup --prover-url=${{ env.prover_url }} --core-url=${{ env.core_url }} - name: Lints run: | - ci_run zk_supervisor fmt --check - ci_run zk_supervisor lint -t md --check - ci_run zk_supervisor lint -t sol --check - ci_run zk_supervisor lint -t js --check - ci_run zk_supervisor lint -t ts --check - ci_run zk_supervisor lint -t rs --check + ci_run zkstack dev fmt --check + ci_run zkstack dev lint -t md --check + ci_run zkstack dev lint -t sol --check + ci_run zkstack dev lint -t js --check + ci_run zkstack dev lint -t ts --check + ci_run zkstack dev lint -t rs --check - name: Check Database run: | - ci_run zk_supervisor database check-sqlx-data --prover-url=${{ env.prover_url }} --core-url=${{ env.core_url }} + ci_run zkstack dev database check-sqlx-data --prover-url=${{ env.prover_url }} --core-url=${{ env.core_url }} diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index b2044d025c4c..9aaa476d740d 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -56,15 +56,22 @@ jobs: - name: Init run: | ci_run run_retried rustup show - ci_run ./bin/zkt - ci_run zk_supervisor contracts + + - name: Install zkstack + run: | + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup + ci_run zkstackup -g --local + + - name: Build contracts + run: | + ci_run zkstack dev contracts - name: Contracts unit tests run: ci_run yarn l1-contracts test - name: Rust unit tests run: | - ci_run zk_supervisor test rust + ci_run zkstack dev test rust # Benchmarks are not tested by `cargo nextest` unless specified explicitly, and even then `criterion` harness is incompatible # with how `cargo nextest` runs tests. Thus, we run criterion-based benchmark tests manually. ci_run cargo test --release -p vm-benchmark --bench oneshot --bench batch @@ -113,8 +120,15 @@ jobs: ci_run git config --global --add safe.directory /usr/src/zksync/contracts/system-contracts ci_run git config --global --add safe.directory /usr/src/zksync/contracts - ci_run ./bin/zkt - ci_run zk_inception chain create \ + - name: Install zkstack + run: | + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup || true + ci_run zkstackup -g --local + + + - name: Create and initialize legacy chain + run: | + ci_run zkstack chain create \ --chain-name legacy \ --chain-id sequential \ --prover-mode no-proofs \ @@ -127,18 +141,18 @@ jobs: --ignore-prerequisites \ --legacy-bridge - ci_run zk_inception ecosystem init --dev --verbose - ci_run zk_supervisor contracts --test-contracts + ci_run zkstack ecosystem init --dev --verbose + ci_run zkstack dev contracts --test-contracts # `sleep 60` because we need to wait until server added all the tokens - name: Run server run: | - ci_run zk_supervisor config-writer --path ${{ matrix.vm_mode == 'NEW' && 'etc/env/file_based/overrides/tests/loadtest-new.yaml' || 'etc/env/file_based/overrides/tests/loadtest-old.yaml' }} --chain legacy - ci_run zk_inception server --uring --chain=legacy --components api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads &>server.log & + ci_run zkstack dev config-writer --path ${{ matrix.vm_mode == 'NEW' && 'etc/env/file_based/overrides/tests/loadtest-new.yaml' || 'etc/env/file_based/overrides/tests/loadtest-old.yaml' }} --chain legacy + ci_run zkstack server --uring --chain=legacy --components api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads &>server.log & ci_run sleep 60 - name: Perform loadtest - run: ci_run zk_supervisor t loadtest -v --chain=legacy + run: ci_run zkstack dev t loadtest -v --chain=legacy - name: Show server.log logs if: always() @@ -175,9 +189,11 @@ jobs: run: | ci_localnet_up - - name: Build zk_toolbox - run: ci_run bash -c "./bin/zkt" - + - name: Install zkstack + run: | + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup || true + ci_run zkstackup -g --local + - name: Create log directories run: | SERVER_LOGS_DIR=logs/server @@ -213,7 +229,7 @@ jobs: ci_run git config --global --add safe.directory /usr/src/zksync/contracts/system-contracts ci_run git config --global --add safe.directory /usr/src/zksync/contracts - ci_run zk_inception ecosystem init --deploy-paymaster --deploy-erc20 \ + ci_run zkstack ecosystem init --deploy-paymaster --deploy-erc20 \ --deploy-ecosystem --l1-rpc-url=http://localhost:8545 \ --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ --server-db-name=zksync_server_localhost_era \ @@ -228,7 +244,7 @@ jobs: - name: Create and initialize Validium chain run: | - ci_run zk_inception chain create \ + ci_run zkstack chain create \ --chain-name validium \ --chain-id sequential \ --prover-mode no-proofs \ @@ -240,7 +256,7 @@ jobs: --set-as-default false \ --ignore-prerequisites - ci_run zk_inception chain init \ + ci_run zkstack chain init \ --deploy-paymaster \ --l1-rpc-url=http://localhost:8545 \ --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ @@ -249,7 +265,7 @@ jobs: - name: Create and initialize chain with Custom Token run: | - ci_run zk_inception chain create \ + ci_run zkstack chain create \ --chain-name custom_token \ --chain-id sequential \ --prover-mode no-proofs \ @@ -261,7 +277,7 @@ jobs: --set-as-default false \ --ignore-prerequisites - ci_run zk_inception chain init \ + ci_run zkstack chain init \ --deploy-paymaster \ --l1-rpc-url=http://localhost:8545 \ --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ @@ -270,7 +286,7 @@ jobs: - name: Create and register chain with transactions signed "offline" run: | - ci_run zk_inception chain create \ + ci_run zkstack chain create \ --chain-name offline_chain \ --chain-id sequential \ --prover-mode no-proofs \ @@ -282,11 +298,11 @@ jobs: --set-as-default false \ --ignore-prerequisites - ci_run zk_inception chain build-transactions --chain offline_chain --l1-rpc-url http://127.0.0.1:8545 + ci_run zkstack chain build-transactions --chain offline_chain --l1-rpc-url http://127.0.0.1:8545 governor_pk=$(awk '/governor:/ {flag=1} flag && /private_key:/ {print $2; exit}' ./configs/wallets.yaml) - ci_run zk_supervisor send-transactions \ + ci_run zkstack dev send-transactions \ --file ./transactions/chain/offline_chain/register-hyperchain-txns.json \ --l1-rpc-url http://127.0.0.1:8545 \ --private-key $governor_pk @@ -305,7 +321,7 @@ jobs: - name: Create and initialize Consensus chain run: | - ci_run zk_inception chain create \ + ci_run zkstack chain create \ --chain-name consensus \ --chain-id sequential \ --prover-mode no-proofs \ @@ -317,7 +333,7 @@ jobs: --set-as-default false \ --ignore-prerequisites - ci_run zk_inception chain init \ + ci_run zkstack chain init \ --deploy-paymaster \ --l1-rpc-url=http://localhost:8545 \ --server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \ @@ -331,19 +347,19 @@ jobs: - name: Build test dependencies run: | - ci_run zk_supervisor test build + ci_run zkstack dev test build - name: Initialize Contract verifier run: | - ci_run zk_inception contract-verifier init --zksolc-version=v1.5.3 --zkvyper-version=v1.5.4 --solc-version=0.8.26 --vyper-version=v0.3.10 --era-vm-solc-version=0.8.26-1.0.1 --only --chain era - ci_run zk_inception contract-verifier run --chain era &> ${{ env.SERVER_LOGS_DIR }}/contract-verifier-rollup.log & + ci_run zkstack contract-verifier init --zksolc-version=v1.5.3 --zkvyper-version=v1.5.4 --solc-version=0.8.26 --vyper-version=v0.3.10 --era-vm-solc-version=0.8.26-1.0.1 --only --chain era + ci_run zkstack contract-verifier run --chain era &> ${{ env.SERVER_LOGS_DIR }}/contract-verifier-rollup.log & - name: Run servers run: | - ci_run zk_inception server --ignore-prerequisites --chain era &> ${{ env.SERVER_LOGS_DIR }}/rollup.log & - ci_run zk_inception server --ignore-prerequisites --chain validium &> ${{ env.SERVER_LOGS_DIR }}/validium.log & - ci_run zk_inception server --ignore-prerequisites --chain custom_token &> ${{ env.SERVER_LOGS_DIR }}/custom_token.log & - ci_run zk_inception server --ignore-prerequisites --chain consensus \ + ci_run zkstack server --ignore-prerequisites --chain era &> ${{ env.SERVER_LOGS_DIR }}/rollup.log & + ci_run zkstack server --ignore-prerequisites --chain validium &> ${{ env.SERVER_LOGS_DIR }}/validium.log & + ci_run zkstack server --ignore-prerequisites --chain custom_token &> ${{ env.SERVER_LOGS_DIR }}/custom_token.log & + ci_run zkstack server --ignore-prerequisites --chain consensus \ --components=api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,vm_runner_bwip,vm_playground,da_dispatcher,consensus \ &> ${{ env.SERVER_LOGS_DIR }}/consensus.log & @@ -351,67 +367,67 @@ jobs: - name: Setup attester committee for the consensus chain run: | - ci_run zk_inception consensus set-attester-committee --chain consensus --from-genesis &> ${{ env.INTEGRATION_TESTS_LOGS_DIR }}/consensus.log + ci_run zkstack consensus set-attester-committee --chain consensus --from-genesis &> ${{ env.INTEGRATION_TESTS_LOGS_DIR }}/consensus.log - name: Run integration tests run: | - ci_run ./bin/run_on_all_chains.sh "zk_supervisor test integration --no-deps --ignore-prerequisites" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }} + ci_run ./bin/run_on_all_chains.sh "zkstack dev test integration --no-deps --ignore-prerequisites" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }} - name: Init external nodes run: | - ci_run zk_inception external-node configs --db-url=postgres://postgres:notsecurepassword@localhost:5432 \ + ci_run zkstack external-node configs --db-url=postgres://postgres:notsecurepassword@localhost:5432 \ --db-name=zksync_en_localhost_era_rollup --l1-rpc-url=http://localhost:8545 --chain era - ci_run zk_inception external-node init --ignore-prerequisites --chain era + ci_run zkstack external-node init --ignore-prerequisites --chain era - ci_run zk_inception external-node configs --db-url=postgres://postgres:notsecurepassword@localhost:5432 \ + ci_run zkstack external-node configs --db-url=postgres://postgres:notsecurepassword@localhost:5432 \ --db-name=zksync_en_localhost_era_validium1 --l1-rpc-url=http://localhost:8545 --chain validium - ci_run zk_inception external-node init --ignore-prerequisites --chain validium + ci_run zkstack external-node init --ignore-prerequisites --chain validium - ci_run zk_inception external-node configs --db-url=postgres://postgres:notsecurepassword@localhost:5432 \ + ci_run zkstack external-node configs --db-url=postgres://postgres:notsecurepassword@localhost:5432 \ --db-name=zksync_en_localhost_era_custom_token --l1-rpc-url=http://localhost:8545 --chain custom_token - ci_run zk_inception external-node init --ignore-prerequisites --chain custom_token + ci_run zkstack external-node init --ignore-prerequisites --chain custom_token - ci_run zk_inception external-node configs --db-url=postgres://postgres:notsecurepassword@localhost:5432 \ + ci_run zkstack external-node configs --db-url=postgres://postgres:notsecurepassword@localhost:5432 \ --db-name=zksync_en_localhost_era_consensus --l1-rpc-url=http://localhost:8545 --chain consensus - ci_run zk_inception external-node init --ignore-prerequisites --chain consensus + ci_run zkstack external-node init --ignore-prerequisites --chain consensus - name: Run recovery tests (from snapshot) run: | - ci_run ./bin/run_on_all_chains.sh "zk_supervisor test recovery --snapshot --no-deps --ignore-prerequisites --verbose" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }} + ci_run ./bin/run_on_all_chains.sh "zkstack dev test recovery --snapshot --no-deps --ignore-prerequisites --verbose" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }} - name: Run recovery tests (from genesis) run: | - ci_run ./bin/run_on_all_chains.sh "zk_supervisor test recovery --no-deps --no-kill --ignore-prerequisites --verbose" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }} + ci_run ./bin/run_on_all_chains.sh "zkstack dev test recovery --no-deps --no-kill --ignore-prerequisites --verbose" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }} - name: Run external node server run: | - ci_run zk_inception external-node run --ignore-prerequisites --chain era &> ${{ env.EXTERNAL_NODE_LOGS_DIR }}/rollup.log & - ci_run zk_inception external-node run --ignore-prerequisites --chain validium &> ${{ env.EXTERNAL_NODE_LOGS_DIR }}/validium.log & - ci_run zk_inception external-node run --ignore-prerequisites --chain custom_token &> ${{ env.EXTERNAL_NODE_LOGS_DIR }}/custom_token.log & - ci_run zk_inception external-node run --ignore-prerequisites --chain consensus --enable-consensus &> ${{ env.EXTERNAL_NODE_LOGS_DIR }}/consensus.log & + ci_run zkstack external-node run --ignore-prerequisites --chain era &> ${{ env.EXTERNAL_NODE_LOGS_DIR }}/rollup.log & + ci_run zkstack external-node run --ignore-prerequisites --chain validium &> ${{ env.EXTERNAL_NODE_LOGS_DIR }}/validium.log & + ci_run zkstack external-node run --ignore-prerequisites --chain custom_token &> ${{ env.EXTERNAL_NODE_LOGS_DIR }}/custom_token.log & + ci_run zkstack external-node run --ignore-prerequisites --chain consensus --enable-consensus &> ${{ env.EXTERNAL_NODE_LOGS_DIR }}/consensus.log & - name: Run integration tests en run: | - ci_run ./bin/run_on_all_chains.sh "zk_supervisor test integration --no-deps --ignore-prerequisites --external-node" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }} + ci_run ./bin/run_on_all_chains.sh "zkstack dev test integration --no-deps --ignore-prerequisites --external-node" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }} - name: Fee projection tests run: | ci_run killall -INT zksync_server || true - ci_run ./bin/run_on_all_chains.sh "zk_supervisor test fees --no-deps --no-kill" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }} + ci_run ./bin/run_on_all_chains.sh "zkstack dev test fees --no-deps --no-kill" ${{ env.CHAINS }} ${{ env.FEES_LOGS_DIR }} - name: Run revert tests run: | ci_run killall -INT zksync_server || true ci_run killall -INT zksync_external_node || true - ci_run ./bin/run_on_all_chains.sh "zk_supervisor test revert --no-deps --external-node --no-kill --ignore-prerequisites" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }} + ci_run ./bin/run_on_all_chains.sh "zkstack dev test revert --no-deps --external-node --no-kill --ignore-prerequisites" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }} # Upgrade tests should run last, because as soon as they # finish the bootloader will be different # TODO make upgrade tests safe to run multiple times - name: Run upgrade test run: | - ci_run zk_supervisor test upgrade --no-deps --chain era + ci_run zkstack dev test upgrade --no-deps --chain era - name: Upload logs diff --git a/.github/workflows/ci-docs-reusable.yml b/.github/workflows/ci-docs-reusable.yml index 5b1d5a9bcdfa..e1a9cf78df7d 100644 --- a/.github/workflows/ci-docs-reusable.yml +++ b/.github/workflows/ci-docs-reusable.yml @@ -27,12 +27,17 @@ jobs: run_retried docker compose pull zk docker compose up -d zk + - name: Install zkstack + run: | + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup + ci_run zkstackup -g --local + - name: Build run: | - ci_run ./bin/zkt ci_run yarn install ci_run git config --global --add safe.directory /usr/src/zksync - name: Lints run: | - ci_run zk_supervisor lint -t md --check + ci_run zkstack dev fmt --check + ci_run zkstack dev lint -t md --check diff --git a/.github/workflows/ci-prover-reusable.yml b/.github/workflows/ci-prover-reusable.yml index 3f842b23488e..6cb9c26d21e7 100644 --- a/.github/workflows/ci-prover-reusable.yml +++ b/.github/workflows/ci-prover-reusable.yml @@ -30,10 +30,14 @@ jobs: mkdir -p ./volumes/postgres docker-compose -f ${RUNNER_COMPOSE_FILE} up --build -d zk postgres - - name: Init + - name: Install zkstack + run: | + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup + ci_run zkstackup -g --local + + - name: Database setup run: | - ci_run zkt - ci_run zk_supervisor db setup --prover-url=${{ env.prover_url }} --core-url=${{ env.core_url }} + ci_run zkstack dev db setup --prover-url=${{ env.prover_url }} --core-url=${{ env.core_url }} - name: Formatting run: ci_run bash -c "cd prover && cargo fmt --check" @@ -65,12 +69,16 @@ jobs: mkdir -p ./volumes/postgres docker-compose -f ${RUNNER_COMPOSE_FILE} up --build -d zk postgres + - name: Install zkstack + run: | + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup || true + ci_run zkstackup -g --local + - name: Init run: | - ci_run zkt ci_run run_retried rustup show - name: Prover unit tests run: | # Not all tests are enabled, since prover and setup_key_generator_and_server requires bellman-cuda to be present - ci_run zk_supervisor test prover + ci_run zkstack dev test prover diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a27a719aeb6..fd9dedf8af4e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: outputs: core: ${{ steps.changed-files.outputs.core_any_changed }} prover: ${{ steps.changed-files.outputs.prover_any_changed }} - zk_toolbox: ${{ steps.changed-files.outputs.zk_toolbox_any_changed }} + zkstack_cli: ${{ steps.changed-files.outputs.zkstack_cli_any_changed }} docs: ${{ steps.changed-files.outputs.docs_any_changed }} all: ${{ steps.changed-files.outputs.all_any_changed }} steps: @@ -58,7 +58,7 @@ jobs: - '.github/workflows/ci-core-lint-reusable.yml' - 'Cargo.toml' - 'Cargo.lock' - - 'zk_toolbox/**' + - 'zkstack_cli/**' - '!**/*.md' - '!**/*.MD' - 'docker-compose.yml' diff --git a/.github/workflows/new-build-contract-verifier-template.yml b/.github/workflows/new-build-contract-verifier-template.yml index 7002d89c3f29..665d82b63eea 100644 --- a/.github/workflows/new-build-contract-verifier-template.yml +++ b/.github/workflows/new-build-contract-verifier-template.yml @@ -38,6 +38,7 @@ jobs: echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV echo CI=1 >> $GITHUB_ENV echo $(pwd)/bin >> $GITHUB_PATH + echo $HOME/.local/bin >> $GITHUB_PATH echo CI=1 >> .env echo IN_DOCKER=1 >> .env @@ -136,13 +137,17 @@ jobs: run: | mkdir -p ./volumes/postgres docker compose up -d postgres - zkt || true + + - name: Install zkstack + run: | + ./zkstack_cli/zkstackup/install --path ./zkstack_cli/zkstackup/zkstackup + zkstackup --local || true - name: build contracts shell: bash run: | cp etc/tokens/{test,localhost}.json - zk_supervisor contracts + zkstack dev contracts - name: Upload contracts uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 diff --git a/.github/workflows/new-build-core-template.yml b/.github/workflows/new-build-core-template.yml index 746150e5596b..f722bbf859d3 100644 --- a/.github/workflows/new-build-core-template.yml +++ b/.github/workflows/new-build-core-template.yml @@ -43,6 +43,7 @@ jobs: echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV echo CI=1 >> $GITHUB_ENV echo $(pwd)/bin >> $GITHUB_PATH + echo $HOME/.local/bin >> $GITHUB_PATH echo CI=1 >> .env echo IN_DOCKER=1 >> .env @@ -141,13 +142,17 @@ jobs: run: | mkdir -p ./volumes/postgres docker compose up -d postgres - zkt || true + - name: Install zkstack + run: | + ./zkstack_cli/zkstackup/install --path ./zkstack_cli/zkstackup/zkstackup + zkstackup --local || true + - name: build contracts shell: bash run: | cp etc/tokens/{test,localhost}.json - zk_supervisor contracts + zkstack dev contracts - name: Upload contracts uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 diff --git a/.github/workflows/new-build-prover-template.yml b/.github/workflows/new-build-prover-template.yml index 60c152213e60..944551c98717 100644 --- a/.github/workflows/new-build-prover-template.yml +++ b/.github/workflows/new-build-prover-template.yml @@ -40,7 +40,7 @@ on: jobs: get-protocol-version: name: Get protocol version - runs-on: [ matterlabs-ci-runner-high-performance ] + runs-on: [matterlabs-ci-runner-high-performance] outputs: protocol_version: ${{ steps.protocolversion.outputs.protocol_version }} steps: @@ -86,7 +86,7 @@ jobs: needs: get-protocol-version env: PROTOCOL_VERSION: ${{ needs.get-protocol-version.outputs.protocol_version }} - runs-on: [ matterlabs-ci-runner-high-performance ] + runs-on: [matterlabs-ci-runner-high-performance] strategy: matrix: components: @@ -96,6 +96,7 @@ jobs: - prover-fri-gateway - prover-job-monitor - proof-fri-gpu-compressor + - prover-autoscaler steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 with: @@ -166,7 +167,7 @@ jobs: copy-images: name: Copy images between docker registries - needs: [ build-images, get-protocol-version ] + needs: [build-images, get-protocol-version] env: PROTOCOL_VERSION: ${{ needs.get-protocol-version.outputs.protocol_version }} runs-on: matterlabs-ci-runner diff --git a/.github/workflows/release-test-stage.yml b/.github/workflows/release-test-stage.yml index 11a844fdd2ba..5767584d5e19 100644 --- a/.github/workflows/release-test-stage.yml +++ b/.github/workflows/release-test-stage.yml @@ -39,7 +39,7 @@ jobs: - '!prover/**' setup: name: Setup - runs-on: [ matterlabs-deployer-stage ] + runs-on: [matterlabs-deployer-stage] outputs: image_tag_suffix: ${{ steps.generate-tag-suffix.outputs.image_tag_suffix }} prover_fri_gpu_key_id: ${{ steps.extract-prover-fri-setup-key-ids.outputs.gpu_short_commit_sha }} @@ -58,11 +58,10 @@ jobs: run: | ./prover/extract-setup-data-keys.sh >> $GITHUB_OUTPUT - build-push-core-images: name: Build and push images - needs: [ setup, changed_files ] - uses: ./.github/workflows/build-core-template.yml + needs: [setup, changed_files] + uses: ./.github/workflows/new-build-core-template.yml if: needs.changed_files.outputs.core == 'true' || needs.changed_files.outputs.all == 'true' with: image_tag_suffix: ${{ needs.setup.outputs.image_tag_suffix }} @@ -72,7 +71,7 @@ jobs: build-push-tee-prover-images: name: Build and push images - needs: [ setup, changed_files ] + needs: [setup, changed_files] uses: ./.github/workflows/build-tee-prover-template.yml if: needs.changed_files.outputs.core == 'true' || needs.changed_files.outputs.all == 'true' with: @@ -84,8 +83,8 @@ jobs: build-push-contract-verifier: name: Build and push images - needs: [ setup, changed_files ] - uses: ./.github/workflows/build-contract-verifier-template.yml + needs: [setup, changed_files] + uses: ./.github/workflows/new-build-contract-verifier-template.yml if: needs.changed_files.outputs.core == 'true' || needs.changed_files.outputs.all == 'true' with: image_tag_suffix: ${{ needs.setup.outputs.image_tag_suffix }} @@ -95,8 +94,8 @@ jobs: build-push-prover-images: name: Build and push images - needs: [ setup, changed_files ] - uses: ./.github/workflows/build-prover-template.yml + needs: [setup, changed_files] + uses: ./.github/workflows/new-build-prover-template.yml if: needs.changed_files.outputs.prover == 'true' || needs.changed_files.outputs.all == 'true' with: image_tag_suffix: ${{ needs.setup.outputs.image_tag_suffix }} @@ -108,12 +107,11 @@ jobs: build-push-witness-generator-image-avx512: name: Build and push prover images with avx512 instructions - needs: [ setup, changed_files ] - uses: ./.github/workflows/build-witness-generator-template.yml + needs: [setup, changed_files] + uses: ./.github/workflows/new-build-witness-generator-template.yml if: needs.changed_files.outputs.prover == 'true' || needs.changed_files.outputs.all == 'true' with: image_tag_suffix: ${{ needs.setup.outputs.image_tag_suffix }}-avx512 - ERA_BELLMAN_CUDA_RELEASE: ${{ vars.ERA_BELLMAN_CUDA_RELEASE }} CUDA_ARCH: "60;70;75;80;89" WITNESS_GENERATOR_RUST_FLAGS: "-Ctarget_feature=+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512vl " secrets: @@ -122,7 +120,7 @@ jobs: build-gar-prover-fri-gpu-and-circuit-prover-gpu-gar: name: Build GAR prover FRI GPU - needs: [ setup, build-push-prover-images ] + needs: [setup, build-push-prover-images] uses: ./.github/workflows/build-prover-fri-gpu-gar-and-circuit-prover-gpu-gar.yml if: needs.changed_files.outputs.prover == 'true' || needs.changed_files.outputs.all == 'true' with: diff --git a/.github/workflows/vm-perf-comparison.yml b/.github/workflows/vm-perf-comparison.yml index 6e044287ad3d..ccf8f370267d 100644 --- a/.github/workflows/vm-perf-comparison.yml +++ b/.github/workflows/vm-perf-comparison.yml @@ -35,6 +35,7 @@ jobs: touch .env echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV echo $(pwd)/bin >> $GITHUB_PATH + echo $(pwd)/zkstack_cli/zkstackup >> $GITHUB_PATH echo "SCCACHE_GCS_BUCKET=matterlabs-infra-sccache-storage" >> .env echo "SCCACHE_GCS_SERVICE_ACCOUNT=gha-ci-runners@matterlabs-infra.iam.gserviceaccount.com" >> .env echo "SCCACHE_GCS_RW_MODE=READ_WRITE" >> .env @@ -44,12 +45,12 @@ jobs: run: | run_retried docker compose pull zk docker compose up -d zk - + - name: run benchmarks on base branch shell: bash run: | - ci_run zkt - ci_run zk_supervisor contracts --system-contracts + ci_run zkt || ci_run zkstackup -g --local # TODO remove zkt in an upcoming PR + ci_run zk_supervisor contracts --system-contracts || ci_run zkstack dev contracts --system-contracts # TODO remove zk_supervisor in an upcoming PR ci_run cargo bench --package vm-benchmark --bench iai | tee base-iai ci_run cargo run --package vm-benchmark --release --bin instruction_counts | tee base-opcodes || touch base-opcodes @@ -60,8 +61,8 @@ jobs: - name: run benchmarks on PR shell: bash run: | - ci_run zkt - ci_run zk_supervisor contracts --system-contracts + ci_run zkstackup -g --local + ci_run zkstack dev contracts --system-contracts ci_run cargo bench --package vm-benchmark --bench iai | tee pr-iai ci_run cargo run --package vm-benchmark --release --bin instruction_counts | tee pr-opcodes || touch pr-opcodes diff --git a/.github/workflows/vm-perf-to-prometheus.yml b/.github/workflows/vm-perf-to-prometheus.yml index 4c8c90a0d8f2..3a2008e1f8e2 100644 --- a/.github/workflows/vm-perf-to-prometheus.yml +++ b/.github/workflows/vm-perf-to-prometheus.yml @@ -28,13 +28,20 @@ jobs: echo "RUSTC_WRAPPER=sccache" >> .env echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV echo $(pwd)/bin >> $GITHUB_PATH + + - name: Install zkstack + run: | + ci_run ./zkstack_cli/zkstackup/install -g --path ./zkstack_cli/zkstackup/zkstackup || true + ci_run zkstackup -g --local - name: init run: | run_retried docker compose pull zk docker compose up -d zk - ci_run zkt - ci_run zk_supervisor contracts + + - name: build contracts + run: | + ci_run zkstack dev contracts - name: run benchmarks run: | diff --git a/.gitignore b/.gitignore index bbd13e2319af..86ed40c70417 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,7 @@ Cargo.lock !/Cargo.lock !/infrastructure/zksync-crypto/Cargo.lock !/prover/Cargo.lock -!/zk_toolbox/Cargo.lock +!/zkstack_cli/Cargo.lock /etc/env/target/* /etc/env/.current @@ -112,7 +112,7 @@ hyperchain-*.yml prover/crates/bin/vk_setup_data_generator_server_fri/data/setup_* prover/data/keys/setup_* -# Zk Toolbox +# ZK Stack CLI chains/era/configs/* chains/gateway/* configs/* diff --git a/Cargo.lock b/Cargo.lock index bd9f2d5ef28d..f9f7a88764ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1539,6 +1539,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "const-decoder" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b381abde2cdc1bc3817e394b24e05667a2dc89f37570cbd34d9c397d99e56e3f" +dependencies = [ + "compile-fmt", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -10488,6 +10497,7 @@ dependencies = [ "itertools 0.10.5", "once_cell", "pretty_assertions", + "test-casing", "thiserror", "tracing", "vise", @@ -10515,6 +10525,7 @@ dependencies = [ "async-trait", "axum", "chrono", + "const-decoder", "futures 0.3.30", "governor", "hex", diff --git a/Cargo.toml b/Cargo.toml index d597f4af7542..60b5628f4191 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -114,6 +114,7 @@ blake2 = "0.10" chrono = "0.4" clap = "4.2.2" codegen = "0.2.0" +const-decoder = "0.4.0" criterion = "0.4.0" ctrlc = "3.1" dashmap = "5.5.3" diff --git a/bin/zk b/bin/zk index 868c4e338cdf..f3b927de8f8e 100755 --- a/bin/zk +++ b/bin/zk @@ -39,6 +39,7 @@ check_yarn_version() { # and it will be hard for them to see what went wrong. check_subdirectory check_yarn_version + if [ -z "$1" ]; then cd $ZKSYNC_HOME run_retried yarn install --frozen-lockfile && yarn utils build && yarn zk build diff --git a/bin/zkt b/bin/zkt deleted file mode 100755 index f781ca67528b..000000000000 --- a/bin/zkt +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -cd $(dirname $0) - -if which zkup >/dev/null; then - cargo uninstall zk_inception - cargo uninstall zk_supervisor - git config --local core.hooksPath || - git config --local core.hooksPath ./.githooks - zkup -p .. --alias -else - echo zkup is not installed, please install it https://github.com/matter-labs/zksync-era/tree/main/zk_toolbox/zkup - cd ../zk_toolbox - cargo install --path ./crates/zk_inception --force - cargo install --path ./crates/zk_supervisor --force -fi - diff --git a/core/lib/config/src/configs/consensus.rs b/core/lib/config/src/configs/consensus.rs index 918d8f4adab9..7f5a0f56aa17 100644 --- a/core/lib/config/src/configs/consensus.rs +++ b/core/lib/config/src/configs/consensus.rs @@ -115,6 +115,7 @@ impl RpcConfig { /// Config (shared between main node and external node). #[derive(Clone, Debug, PartialEq)] pub struct ConsensusConfig { + pub port: Option, /// Local socket address to listen for the incoming connections. pub server_addr: std::net::SocketAddr, /// Public address of this node (should forward to `server_addr`) diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index a6ff30e04a90..960808aa6a69 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -802,6 +802,7 @@ impl Distribution for EncodeDist { fn sample(&self, rng: &mut R) -> configs::consensus::ConsensusConfig { use configs::consensus::{ConsensusConfig, Host, NodePublicKey}; ConsensusConfig { + port: self.sample(rng), server_addr: self.sample(rng), public_addr: Host(self.sample(rng)), max_payload_size: self.sample(rng), diff --git a/core/lib/dal/.sqlx/query-369f8f652335176ab22ee45fd6f1717e73c5e6b063be3553d82bfecb98334980.json b/core/lib/dal/.sqlx/query-369f8f652335176ab22ee45fd6f1717e73c5e6b063be3553d82bfecb98334980.json deleted file mode 100644 index 7245fa3059ed..000000000000 --- a/core/lib/dal/.sqlx/query-369f8f652335176ab22ee45fd6f1717e73c5e6b063be3553d82bfecb98334980.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n bytecode\n FROM\n (\n SELECT\n *\n FROM\n storage_logs\n WHERE\n storage_logs.hashed_key = $1\n AND storage_logs.miniblock_number <= $2\n ORDER BY\n storage_logs.miniblock_number DESC,\n storage_logs.operation_number DESC\n LIMIT\n 1\n ) t\n JOIN factory_deps ON value = factory_deps.bytecode_hash\n WHERE\n value != $3\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "bytecode", - "type_info": "Bytea" - } - ], - "parameters": { - "Left": [ - "Bytea", - "Int8", - "Bytea" - ] - }, - "nullable": [ - false - ] - }, - "hash": "369f8f652335176ab22ee45fd6f1717e73c5e6b063be3553d82bfecb98334980" -} diff --git a/core/lib/dal/.sqlx/query-c61b15a9591e65eab7d226f5b9035bfda52cc5bb5a4bfb11270a2a784491c967.json b/core/lib/dal/.sqlx/query-c61b15a9591e65eab7d226f5b9035bfda52cc5bb5a4bfb11270a2a784491c967.json new file mode 100644 index 000000000000..20b791991650 --- /dev/null +++ b/core/lib/dal/.sqlx/query-c61b15a9591e65eab7d226f5b9035bfda52cc5bb5a4bfb11270a2a784491c967.json @@ -0,0 +1,30 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n bytecode_hash,\n bytecode\n FROM\n (\n SELECT\n value\n FROM\n storage_logs\n WHERE\n storage_logs.hashed_key = $1\n AND storage_logs.miniblock_number <= $2\n ORDER BY\n storage_logs.miniblock_number DESC,\n storage_logs.operation_number DESC\n LIMIT\n 1\n ) deploy_log\n JOIN factory_deps ON value = factory_deps.bytecode_hash\n WHERE\n value != $3\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "bytecode_hash", + "type_info": "Bytea" + }, + { + "ordinal": 1, + "name": "bytecode", + "type_info": "Bytea" + } + ], + "parameters": { + "Left": [ + "Bytea", + "Int8", + "Bytea" + ] + }, + "nullable": [ + false, + false + ] + }, + "hash": "c61b15a9591e65eab7d226f5b9035bfda52cc5bb5a4bfb11270a2a784491c967" +} diff --git a/core/lib/dal/src/blocks_dal.rs b/core/lib/dal/src/blocks_dal.rs index 347152e3c38d..d59f95192c6b 100644 --- a/core/lib/dal/src/blocks_dal.rs +++ b/core/lib/dal/src/blocks_dal.rs @@ -578,11 +578,14 @@ impl BlocksDal<'_, '_> { /// null or set to default value for the corresponding type). pub async fn insert_l1_batch( &mut self, - number: L1BatchNumber, - timestamp: u64, - protocol_version: Option, - fee_address: Address, - batch_fee_input: BatchFeeInput, + unsealed_batch_header: UnsealedL1BatchHeader, + ) -> DalResult<()> { + Self::insert_l1_batch_inner(unsealed_batch_header, self.storage).await + } + + async fn insert_l1_batch_inner( + unsealed_batch_header: UnsealedL1BatchHeader, + conn: &mut Connection<'_, Core>, ) -> DalResult<()> { sqlx::query!( r#" @@ -625,21 +628,51 @@ impl BlocksDal<'_, '_> { FALSE ) "#, - i64::from(number.0), - timestamp as i64, - protocol_version.map(|v| v as i32), - fee_address.as_bytes(), - batch_fee_input.l1_gas_price() as i64, - batch_fee_input.fair_l2_gas_price() as i64, - batch_fee_input.fair_pubdata_price() as i64, + i64::from(unsealed_batch_header.number.0), + unsealed_batch_header.timestamp as i64, + unsealed_batch_header.protocol_version.map(|v| v as i32), + unsealed_batch_header.fee_address.as_bytes(), + unsealed_batch_header.fee_input.l1_gas_price() as i64, + unsealed_batch_header.fee_input.fair_l2_gas_price() as i64, + unsealed_batch_header.fee_input.fair_pubdata_price() as i64, ) .instrument("insert_l1_batch") - .with_arg("number", &number) - .execute(self.storage) + .with_arg("number", &unsealed_batch_header.number) + .execute(conn) .await?; Ok(()) } + pub async fn ensure_unsealed_l1_batch_exists( + &mut self, + unsealed_batch: UnsealedL1BatchHeader, + ) -> anyhow::Result<()> { + let mut transaction = self.storage.start_transaction().await?; + let unsealed_batch_fetched = Self::get_unsealed_l1_batch_inner(&mut transaction).await?; + + match unsealed_batch_fetched { + None => { + tracing::info!( + "Unsealed batch #{} could not be found; inserting", + unsealed_batch.number + ); + Self::insert_l1_batch_inner(unsealed_batch, &mut transaction).await?; + } + Some(unsealed_batch_fetched) => { + if unsealed_batch_fetched.number != unsealed_batch.number { + anyhow::bail!( + "fetched unsealed L1 batch #{} does not conform to expected L1 batch #{}", + unsealed_batch_fetched.number, + unsealed_batch.number + ) + } + } + } + + transaction.commit().await?; + Ok(()) + } + /// Marks provided L1 batch as sealed and populates it with all the runtime information. /// /// Errors if the batch does not exist. @@ -744,6 +777,12 @@ impl BlocksDal<'_, '_> { } pub async fn get_unsealed_l1_batch(&mut self) -> DalResult> { + Self::get_unsealed_l1_batch_inner(self.storage).await + } + + async fn get_unsealed_l1_batch_inner( + conn: &mut Connection<'_, Core>, + ) -> DalResult> { let batch = sqlx::query_as!( UnsealedStorageL1Batch, r#" @@ -761,8 +800,8 @@ impl BlocksDal<'_, '_> { NOT is_sealed "#, ) - .instrument("get_last_committed_to_eth_l1_batch") - .fetch_optional(self.storage) + .instrument("get_unsealed_l1_batch") + .fetch_optional(conn) .await?; Ok(batch.map(|b| b.into())) @@ -2621,11 +2660,7 @@ impl BlocksDal<'_, '_> { pub async fn insert_mock_l1_batch(&mut self, header: &L1BatchHeader) -> anyhow::Result<()> { self.insert_l1_batch( - header.number, - header.timestamp, - header.protocol_version, - header.fee_address, - BatchFeeInput::pubdata_independent(100, 100, 100), + header.to_unsealed_header(BatchFeeInput::pubdata_independent(100, 100, 100)), ) .await?; self.mark_l1_batch_as_sealed( @@ -2940,11 +2975,7 @@ mod tests { }; conn.blocks_dal() .insert_l1_batch( - header.number, - header.timestamp, - header.protocol_version, - header.fee_address, - BatchFeeInput::pubdata_independent(100, 100, 100), + header.to_unsealed_header(BatchFeeInput::pubdata_independent(100, 100, 100)), ) .await .unwrap(); @@ -2958,11 +2989,7 @@ mod tests { predicted_gas += predicted_gas; conn.blocks_dal() .insert_l1_batch( - header.number, - header.timestamp, - header.protocol_version, - header.fee_address, - BatchFeeInput::pubdata_independent(100, 100, 100), + header.to_unsealed_header(BatchFeeInput::pubdata_independent(100, 100, 100)), ) .await .unwrap(); diff --git a/core/lib/dal/src/storage_web3_dal.rs b/core/lib/dal/src/storage_web3_dal.rs index 78c1dc0c3d0d..10d2cfe61525 100644 --- a/core/lib/dal/src/storage_web3_dal.rs +++ b/core/lib/dal/src/storage_web3_dal.rs @@ -15,6 +15,13 @@ use zksync_utils::h256_to_u256; use crate::{models::storage_block::ResolvedL1BatchForL2Block, Core, CoreDal}; +/// Raw bytecode information returned by [`StorageWeb3Dal::get_contract_code_unchecked()`]. +#[derive(Debug)] +pub struct RawBytecode { + pub bytecode_hash: H256, + pub bytecode: Vec, +} + #[derive(Debug)] pub struct StorageWeb3Dal<'a, 'c> { pub(crate) storage: &'a mut Connection<'c, Core>, @@ -234,16 +241,17 @@ impl StorageWeb3Dal<'_, '_> { &mut self, address: Address, block_number: L2BlockNumber, - ) -> DalResult>> { + ) -> DalResult> { let hashed_key = get_code_key(&address).hashed_key(); let row = sqlx::query!( r#" SELECT + bytecode_hash, bytecode FROM ( SELECT - * + value FROM storage_logs WHERE @@ -254,7 +262,7 @@ impl StorageWeb3Dal<'_, '_> { storage_logs.operation_number DESC LIMIT 1 - ) t + ) deploy_log JOIN factory_deps ON value = factory_deps.bytecode_hash WHERE value != $3 @@ -268,7 +276,11 @@ impl StorageWeb3Dal<'_, '_> { .with_arg("block_number", &block_number) .fetch_optional(self.storage) .await?; - Ok(row.map(|row| row.bytecode)) + + Ok(row.map(|row| RawBytecode { + bytecode_hash: H256::from_slice(&row.bytecode_hash), + bytecode: row.bytecode, + })) } /// Given bytecode hash, returns bytecode and L2 block number at which it was inserted. diff --git a/core/lib/multivm/Cargo.toml b/core/lib/multivm/Cargo.toml index ab418d24cd12..e49086a6b8b1 100644 --- a/core/lib/multivm/Cargo.toml +++ b/core/lib/multivm/Cargo.toml @@ -42,5 +42,6 @@ ethabi.workspace = true [dev-dependencies] assert_matches.workspace = true pretty_assertions.workspace = true +test-casing.workspace = true zksync_test_account.workspace = true zksync_eth_signer.workspace = true diff --git a/core/lib/multivm/src/versions/vm_latest/tests/evm_emulator.rs b/core/lib/multivm/src/versions/vm_latest/tests/evm_emulator.rs index ca8157b170d4..34780b73eb05 100644 --- a/core/lib/multivm/src/versions/vm_latest/tests/evm_emulator.rs +++ b/core/lib/multivm/src/versions/vm_latest/tests/evm_emulator.rs @@ -1,28 +1,47 @@ +use std::collections::HashMap; + use ethabi::Token; -use zksync_contracts::read_bytecode; -use zksync_system_constants::{CONTRACT_DEPLOYER_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS}; -use zksync_types::{get_code_key, get_known_code_key, Execute, H256}; -use zksync_utils::{be_words_to_bytes, bytecode::hash_bytecode, h256_to_u256}; -use zksync_vm_interface::VmInterfaceExt; +use test_casing::{test_casing, Product}; +use zksync_contracts::{load_contract, read_bytecode, SystemContractCode}; +use zksync_system_constants::{ + CONTRACT_DEPLOYER_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS, L2_BASE_TOKEN_ADDRESS, +}; +use zksync_test_account::TxType; +use zksync_types::{ + get_code_key, get_known_code_key, + utils::{key_for_eth_balance, storage_key_for_eth_balance}, + AccountTreeId, Address, Execute, StorageKey, H256, U256, +}; +use zksync_utils::{ + be_words_to_bytes, + bytecode::{hash_bytecode, hash_evm_bytecode}, + bytes_to_be_words, h256_to_u256, +}; use crate::{ - interface::{storage::InMemoryStorage, TxExecutionMode}, + interface::{ + storage::InMemoryStorage, TxExecutionMode, VmExecutionResultAndLogs, VmInterfaceExt, + }, versions::testonly::default_system_env, - vm_latest::{tests::tester::VmTesterBuilder, utils::hash_evm_bytecode, HistoryEnabled}, + vm_latest::{ + tests::tester::{VmTester, VmTesterBuilder}, + HistoryEnabled, + }, }; const MOCK_DEPLOYER_PATH: &str = "etc/contracts-test-data/artifacts-zk/contracts/mock-evm/mock-evm.sol/MockContractDeployer.json"; const MOCK_KNOWN_CODE_STORAGE_PATH: &str = "etc/contracts-test-data/artifacts-zk/contracts/mock-evm/mock-evm.sol/MockKnownCodeStorage.json"; +const MOCK_EMULATOR_PATH: &str = + "etc/contracts-test-data/artifacts-zk/contracts/mock-evm/mock-evm.sol/MockEvmEmulator.json"; +const RECURSIVE_CONTRACT_PATH: &str = "etc/contracts-test-data/artifacts-zk/contracts/mock-evm/mock-evm.sol/NativeRecursiveContract.json"; +const INCREMENTING_CONTRACT_PATH: &str = "etc/contracts-test-data/artifacts-zk/contracts/mock-evm/mock-evm.sol/IncrementingContract.json"; -#[test] -fn tracing_evm_contract_deployment() { +fn override_system_contracts(storage: &mut InMemoryStorage) { let mock_deployer = read_bytecode(MOCK_DEPLOYER_PATH); let mock_deployer_hash = hash_bytecode(&mock_deployer); let mock_known_code_storage = read_bytecode(MOCK_KNOWN_CODE_STORAGE_PATH); let mock_known_code_storage_hash = hash_bytecode(&mock_known_code_storage); - // Override - let mut storage = InMemoryStorage::with_system_contracts(hash_bytecode); storage.set_value(get_code_key(&CONTRACT_DEPLOYER_ADDRESS), mock_deployer_hash); storage.set_value( get_known_code_key(&mock_deployer_hash), @@ -38,6 +57,81 @@ fn tracing_evm_contract_deployment() { ); storage.store_factory_dep(mock_deployer_hash, mock_deployer); storage.store_factory_dep(mock_known_code_storage_hash, mock_known_code_storage); +} + +#[derive(Debug)] +struct EvmTestBuilder { + deploy_emulator: bool, + storage: InMemoryStorage, + evm_contract_addresses: Vec
, +} + +impl EvmTestBuilder { + fn new(deploy_emulator: bool, evm_contract_address: Address) -> Self { + Self { + deploy_emulator, + storage: InMemoryStorage::with_system_contracts(hash_bytecode), + evm_contract_addresses: vec![evm_contract_address], + } + } + + fn with_mock_deployer(mut self) -> Self { + override_system_contracts(&mut self.storage); + self + } + + fn with_evm_address(mut self, address: Address) -> Self { + self.evm_contract_addresses.push(address); + self + } + + fn build(self) -> VmTester { + let mock_emulator = read_bytecode(MOCK_EMULATOR_PATH); + let mut storage = self.storage; + let mut system_env = default_system_env(); + if self.deploy_emulator { + let evm_bytecode: Vec<_> = (0..32).collect(); + let evm_bytecode_hash = hash_evm_bytecode(&evm_bytecode); + storage.set_value( + get_known_code_key(&evm_bytecode_hash), + H256::from_low_u64_be(1), + ); + for evm_address in self.evm_contract_addresses { + storage.set_value(get_code_key(&evm_address), evm_bytecode_hash); + } + + system_env.base_system_smart_contracts.evm_emulator = Some(SystemContractCode { + hash: hash_bytecode(&mock_emulator), + code: bytes_to_be_words(mock_emulator), + }); + } else { + let emulator_hash = hash_bytecode(&mock_emulator); + storage.set_value(get_known_code_key(&emulator_hash), H256::from_low_u64_be(1)); + storage.store_factory_dep(emulator_hash, mock_emulator); + + for evm_address in self.evm_contract_addresses { + storage.set_value(get_code_key(&evm_address), emulator_hash); + // Set `isUserSpace` in the emulator storage to `true`, so that it skips emulator-specific checks + storage.set_value( + StorageKey::new(AccountTreeId::new(evm_address), H256::zero()), + H256::from_low_u64_be(1), + ); + } + } + + VmTesterBuilder::new(HistoryEnabled) + .with_system_env(system_env) + .with_storage(storage) + .with_execution_mode(TxExecutionMode::VerifyExecute) + .with_random_rich_accounts(1) + .build() + } +} + +#[test] +fn tracing_evm_contract_deployment() { + let mut storage = InMemoryStorage::with_system_contracts(hash_bytecode); + override_system_contracts(&mut storage); let mut system_env = default_system_env(); // The EVM emulator will not be accessed, so we set it to a dummy value. @@ -51,7 +145,7 @@ fn tracing_evm_contract_deployment() { .build(); let account = &mut vm.rich_accounts[0]; - let args = [Token::Bytes((0..=u8::MAX).collect())]; + let args = [Token::Bytes((0..32).collect())]; let evm_bytecode = ethabi::encode(&args); let expected_bytecode_hash = hash_evm_bytecode(&evm_bytecode); let execute = Execute::for_deploy(expected_bytecode_hash, vec![0; 32], &args); @@ -74,3 +168,343 @@ fn tracing_evm_contract_deployment() { evm_bytecode ); } + +#[test] +fn mock_emulator_basics() { + let called_address = Address::repeat_byte(0x23); + let mut vm = EvmTestBuilder::new(true, called_address).build(); + let account = &mut vm.rich_accounts[0]; + let tx = account.get_l2_tx_for_execute( + Execute { + contract_address: Some(called_address), + calldata: vec![], + value: 0.into(), + factory_deps: vec![], + }, + None, + ); + + let (_, vm_result) = vm + .vm + .execute_transaction_with_bytecode_compression(tx, true); + assert!(!vm_result.result.is_failed(), "{:?}", vm_result.result); +} + +const RECIPIENT_ADDRESS: Address = Address::repeat_byte(0x12); + +/// `deploy_emulator = false` here and below tests the mock emulator as an ordinary contract (i.e., sanity-checks its logic). +#[test_casing(2, [false, true])] +#[test] +fn mock_emulator_with_payment(deploy_emulator: bool) { + let mock_emulator_abi = load_contract(MOCK_EMULATOR_PATH); + let mut vm = EvmTestBuilder::new(deploy_emulator, RECIPIENT_ADDRESS).build(); + + let mut current_balance = U256::zero(); + for i in 1_u64..=5 { + let transferred_value = (1_000_000_000 * i).into(); + let vm_result = test_payment( + &mut vm, + &mock_emulator_abi, + &mut current_balance, + transferred_value, + ); + + let balance_storage_logs = vm_result.logs.storage_logs.iter().filter_map(|log| { + (*log.log.key.address() == L2_BASE_TOKEN_ADDRESS) + .then_some((*log.log.key.key(), h256_to_u256(log.log.value))) + }); + let balances: HashMap<_, _> = balance_storage_logs.collect(); + assert_eq!( + balances[&key_for_eth_balance(&RECIPIENT_ADDRESS)], + current_balance + ); + } +} + +fn test_payment( + vm: &mut VmTester, + mock_emulator_abi: ðabi::Contract, + balance: &mut U256, + transferred_value: U256, +) -> VmExecutionResultAndLogs { + *balance += transferred_value; + let test_payment_fn = mock_emulator_abi.function("testPayment").unwrap(); + let account = &mut vm.rich_accounts[0]; + let tx = account.get_l2_tx_for_execute( + Execute { + contract_address: Some(RECIPIENT_ADDRESS), + calldata: test_payment_fn + .encode_input(&[Token::Uint(transferred_value), Token::Uint(*balance)]) + .unwrap(), + value: transferred_value, + factory_deps: vec![], + }, + None, + ); + + let (_, vm_result) = vm + .vm + .execute_transaction_with_bytecode_compression(tx, true); + assert!(!vm_result.result.is_failed(), "{vm_result:?}"); + vm_result +} + +#[test_casing(4, Product(([false, true], [false, true])))] +#[test] +fn mock_emulator_with_recursion(deploy_emulator: bool, is_external: bool) { + let mock_emulator_abi = load_contract(MOCK_EMULATOR_PATH); + let recipient_address = Address::repeat_byte(0x12); + let mut vm = EvmTestBuilder::new(deploy_emulator, recipient_address).build(); + let account = &mut vm.rich_accounts[0]; + + let test_recursion_fn = mock_emulator_abi + .function(if is_external { + "testExternalRecursion" + } else { + "testRecursion" + }) + .unwrap(); + let mut expected_value = U256::one(); + let depth = 50_u32; + for i in 2..=depth { + expected_value *= i; + } + + let factory_deps = if is_external { + vec![read_bytecode(RECURSIVE_CONTRACT_PATH)] + } else { + vec![] + }; + let tx = account.get_l2_tx_for_execute( + Execute { + contract_address: Some(recipient_address), + calldata: test_recursion_fn + .encode_input(&[Token::Uint(depth.into()), Token::Uint(expected_value)]) + .unwrap(), + value: 0.into(), + factory_deps, + }, + None, + ); + let (_, vm_result) = vm + .vm + .execute_transaction_with_bytecode_compression(tx, true); + assert!(!vm_result.result.is_failed(), "{vm_result:?}"); +} + +#[test] +fn calling_to_mock_emulator_from_native_contract() { + let recipient_address = Address::repeat_byte(0x12); + let mut vm = EvmTestBuilder::new(true, recipient_address).build(); + let account = &mut vm.rich_accounts[0]; + + // Deploy a native contract. + let native_contract = read_bytecode(RECURSIVE_CONTRACT_PATH); + let native_contract_abi = load_contract(RECURSIVE_CONTRACT_PATH); + let deploy_tx = account.get_deploy_tx( + &native_contract, + Some(&[Token::Address(recipient_address)]), + TxType::L2, + ); + let (_, vm_result) = vm + .vm + .execute_transaction_with_bytecode_compression(deploy_tx.tx, true); + assert!(!vm_result.result.is_failed(), "{:?}", vm_result.result); + + // Call from the native contract to the EVM emulator. + let test_fn = native_contract_abi.function("recurse").unwrap(); + let test_tx = account.get_l2_tx_for_execute( + Execute { + contract_address: Some(deploy_tx.address), + calldata: test_fn.encode_input(&[Token::Uint(50.into())]).unwrap(), + value: Default::default(), + factory_deps: vec![], + }, + None, + ); + let (_, vm_result) = vm + .vm + .execute_transaction_with_bytecode_compression(test_tx, true); + assert!(!vm_result.result.is_failed(), "{:?}", vm_result.result); +} + +#[test] +fn mock_emulator_with_deployment() { + let contract_address = Address::repeat_byte(0xaa); + let mut vm = EvmTestBuilder::new(true, contract_address) + .with_mock_deployer() + .build(); + let account = &mut vm.rich_accounts[0]; + + let mock_emulator_abi = load_contract(MOCK_EMULATOR_PATH); + let new_evm_bytecode = vec![0xfe; 96]; + let new_evm_bytecode_hash = hash_evm_bytecode(&new_evm_bytecode); + + let test_fn = mock_emulator_abi.function("testDeploymentAndCall").unwrap(); + let test_tx = account.get_l2_tx_for_execute( + Execute { + contract_address: Some(contract_address), + calldata: test_fn + .encode_input(&[ + Token::FixedBytes(new_evm_bytecode_hash.0.into()), + Token::Bytes(new_evm_bytecode.clone()), + ]) + .unwrap(), + value: 0.into(), + factory_deps: vec![], + }, + None, + ); + let (_, vm_result) = vm + .vm + .execute_transaction_with_bytecode_compression(test_tx, true); + assert!(!vm_result.result.is_failed(), "{vm_result:?}"); + + let factory_deps = vm_result.new_known_factory_deps.unwrap(); + assert_eq!( + factory_deps, + HashMap::from([(new_evm_bytecode_hash, new_evm_bytecode)]) + ); +} + +#[test] +fn mock_emulator_with_delegate_call() { + let evm_contract_address = Address::repeat_byte(0xaa); + let other_evm_contract_address = Address::repeat_byte(0xbb); + let mut builder = EvmTestBuilder::new(true, evm_contract_address); + builder.storage.set_value( + storage_key_for_eth_balance(&evm_contract_address), + H256::from_low_u64_be(1_000_000), + ); + builder.storage.set_value( + storage_key_for_eth_balance(&other_evm_contract_address), + H256::from_low_u64_be(2_000_000), + ); + let mut vm = builder.with_evm_address(other_evm_contract_address).build(); + let account = &mut vm.rich_accounts[0]; + + // Deploy a native contract. + let native_contract = read_bytecode(INCREMENTING_CONTRACT_PATH); + let native_contract_abi = load_contract(INCREMENTING_CONTRACT_PATH); + let deploy_tx = account.get_deploy_tx(&native_contract, None, TxType::L2); + let (_, vm_result) = vm + .vm + .execute_transaction_with_bytecode_compression(deploy_tx.tx, true); + assert!(!vm_result.result.is_failed(), "{:?}", vm_result.result); + + let test_fn = native_contract_abi.function("testDelegateCall").unwrap(); + // Delegate to the native contract from EVM. + test_delegate_call(&mut vm, test_fn, evm_contract_address, deploy_tx.address); + // Delegate to EVM from the native contract. + test_delegate_call(&mut vm, test_fn, deploy_tx.address, evm_contract_address); + // Delegate to EVM from EVM. + test_delegate_call( + &mut vm, + test_fn, + evm_contract_address, + other_evm_contract_address, + ); +} + +fn test_delegate_call( + vm: &mut VmTester, + test_fn: ðabi::Function, + from: Address, + to: Address, +) { + let account = &mut vm.rich_accounts[0]; + let test_tx = account.get_l2_tx_for_execute( + Execute { + contract_address: Some(from), + calldata: test_fn.encode_input(&[Token::Address(to)]).unwrap(), + value: 0.into(), + factory_deps: vec![], + }, + None, + ); + let (_, vm_result) = vm + .vm + .execute_transaction_with_bytecode_compression(test_tx, true); + assert!(!vm_result.result.is_failed(), "{vm_result:?}"); +} + +#[test] +fn mock_emulator_with_static_call() { + let evm_contract_address = Address::repeat_byte(0xaa); + let other_evm_contract_address = Address::repeat_byte(0xbb); + let mut builder = EvmTestBuilder::new(true, evm_contract_address); + builder.storage.set_value( + storage_key_for_eth_balance(&evm_contract_address), + H256::from_low_u64_be(1_000_000), + ); + builder.storage.set_value( + storage_key_for_eth_balance(&other_evm_contract_address), + H256::from_low_u64_be(2_000_000), + ); + // Set differing read values for tested contracts. The slot index is defined in the contract. + let value_slot = H256::from_low_u64_be(0x123); + builder.storage.set_value( + StorageKey::new(AccountTreeId::new(evm_contract_address), value_slot), + H256::from_low_u64_be(100), + ); + builder.storage.set_value( + StorageKey::new(AccountTreeId::new(other_evm_contract_address), value_slot), + H256::from_low_u64_be(200), + ); + let mut vm = builder.with_evm_address(other_evm_contract_address).build(); + let account = &mut vm.rich_accounts[0]; + + // Deploy a native contract. + let native_contract = read_bytecode(INCREMENTING_CONTRACT_PATH); + let native_contract_abi = load_contract(INCREMENTING_CONTRACT_PATH); + let deploy_tx = account.get_deploy_tx(&native_contract, None, TxType::L2); + let (_, vm_result) = vm + .vm + .execute_transaction_with_bytecode_compression(deploy_tx.tx, true); + assert!(!vm_result.result.is_failed(), "{:?}", vm_result.result); + + let test_fn = native_contract_abi.function("testStaticCall").unwrap(); + // Call to the native contract from EVM. + test_static_call(&mut vm, test_fn, evm_contract_address, deploy_tx.address, 0); + // Call to EVM from the native contract. + test_static_call( + &mut vm, + test_fn, + deploy_tx.address, + evm_contract_address, + 100, + ); + // Call to EVM from EVM. + test_static_call( + &mut vm, + test_fn, + evm_contract_address, + other_evm_contract_address, + 200, + ); +} + +fn test_static_call( + vm: &mut VmTester, + test_fn: ðabi::Function, + from: Address, + to: Address, + expected_value: u64, +) { + let account = &mut vm.rich_accounts[0]; + let test_tx = account.get_l2_tx_for_execute( + Execute { + contract_address: Some(from), + calldata: test_fn + .encode_input(&[Token::Address(to), Token::Uint(expected_value.into())]) + .unwrap(), + value: 0.into(), + factory_deps: vec![], + }, + None, + ); + let (_, vm_result) = vm + .vm + .execute_transaction_with_bytecode_compression(test_tx, true); + assert!(!vm_result.result.is_failed(), "{vm_result:?}"); +} diff --git a/core/lib/multivm/src/versions/vm_latest/tracers/evm_deploy_tracer.rs b/core/lib/multivm/src/versions/vm_latest/tracers/evm_deploy_tracer.rs index d91ee13a920a..becc4f225276 100644 --- a/core/lib/multivm/src/versions/vm_latest/tracers/evm_deploy_tracer.rs +++ b/core/lib/multivm/src/versions/vm_latest/tracers/evm_deploy_tracer.rs @@ -8,16 +8,14 @@ use zk_evm_1_5_0::{ }, }; use zksync_types::{CONTRACT_DEPLOYER_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS}; -use zksync_utils::{bytes_to_be_words, h256_to_u256}; +use zksync_utils::{bytecode::hash_evm_bytecode, bytes_to_be_words, h256_to_u256}; use zksync_vm_interface::storage::StoragePtr; use super::{traits::VmTracer, utils::read_pointer}; use crate::{ interface::{storage::WriteStorage, tracer::TracerExecutionStatus}, tracers::dynamic::vm_1_5_0::DynTracer, - vm_latest::{ - utils::hash_evm_bytecode, BootloaderState, HistoryMode, SimpleMemory, ZkSyncVmState, - }, + vm_latest::{BootloaderState, HistoryMode, SimpleMemory, ZkSyncVmState}, }; /// Tracer responsible for collecting information about EVM deploys and providing those diff --git a/core/lib/multivm/src/versions/vm_latest/utils/mod.rs b/core/lib/multivm/src/versions/vm_latest/utils/mod.rs index e07d3eda7c4c..aeb66755f514 100644 --- a/core/lib/multivm/src/versions/vm_latest/utils/mod.rs +++ b/core/lib/multivm/src/versions/vm_latest/utils/mod.rs @@ -1,11 +1,7 @@ //! Utility functions for the VM. use once_cell::sync::Lazy; -use zk_evm_1_5_0::{ - aux_structures::MemoryPage, - sha2, - zkevm_opcode_defs::{BlobSha256Format, VersionedHashLen32}, -}; +use zk_evm_1_5_0::aux_structures::MemoryPage; use zksync_types::{H256, KNOWN_CODES_STORAGE_ADDRESS}; use zksync_vm_interface::VmEvent; @@ -15,22 +11,6 @@ pub(crate) mod logs; pub mod overhead; pub mod transaction_encoding; -pub(crate) fn hash_evm_bytecode(bytecode: &[u8]) -> H256 { - use sha2::{Digest, Sha256}; - let mut hasher = Sha256::new(); - let len = bytecode.len() as u16; - hasher.update(bytecode); - let result = hasher.finalize(); - - let mut output = [0u8; 32]; - output[..].copy_from_slice(result.as_slice()); - output[0] = BlobSha256Format::VERSION_BYTE; - output[1] = 0; - output[2..4].copy_from_slice(&len.to_be_bytes()); - - H256(output) -} - pub const fn heap_page_from_base(base: MemoryPage) -> MemoryPage { MemoryPage(base.0 + 2) } diff --git a/core/lib/protobuf_config/src/consensus.rs b/core/lib/protobuf_config/src/consensus.rs index 81cad437fe4b..2219b6a82ea8 100644 --- a/core/lib/protobuf_config/src/consensus.rs +++ b/core/lib/protobuf_config/src/consensus.rs @@ -148,6 +148,7 @@ impl ProtoRepr for proto::Config { }; Ok(Self::Type { + port: self.port.and_then(|x| x.try_into().ok()), server_addr: required(&self.server_addr) .and_then(|x| Ok(x.parse()?)) .context("server_addr")?, @@ -182,6 +183,7 @@ impl ProtoRepr for proto::Config { fn build(this: &Self::Type) -> Self { Self { + port: this.port.map(|x| x.into()), server_addr: Some(this.server_addr.to_string()), public_addr: Some(this.public_addr.0.clone()), max_payload_size: Some(this.max_payload_size.try_into().unwrap()), diff --git a/core/lib/protobuf_config/src/lib.rs b/core/lib/protobuf_config/src/lib.rs index 48bc5f1ce137..68f7f699de20 100644 --- a/core/lib/protobuf_config/src/lib.rs +++ b/core/lib/protobuf_config/src/lib.rs @@ -64,7 +64,7 @@ pub fn read_optional_repr(field: &Option

) -> Option { .transpose() // This error will printed, only if the config partially filled, allows to debug config issues easier .map_err(|err| { - tracing::error!("Failed to serialize config: {err}"); + tracing::error!("Failed to parse config: {err:#}"); err }) .ok() diff --git a/core/lib/protobuf_config/src/proto/core/consensus.proto b/core/lib/protobuf_config/src/proto/core/consensus.proto index 92527df739aa..9b0d69e7270c 100644 --- a/core/lib/protobuf_config/src/proto/core/consensus.proto +++ b/core/lib/protobuf_config/src/proto/core/consensus.proto @@ -70,6 +70,9 @@ message Config { reserved 3; reserved "validators"; + // Port to listen on, for incoming TCP connections. + optional uint32 port = 12; + // IP:port to listen on, for incoming TCP connections. // Use `0.0.0.0:` to listen on all network interfaces (i.e. on all IPs exposed by this VM). optional string server_addr = 1; // required; IpAddr diff --git a/core/lib/types/src/block.rs b/core/lib/types/src/block.rs index 361e9ea56d28..9211a6f1d8cf 100644 --- a/core/lib/types/src/block.rs +++ b/core/lib/types/src/block.rs @@ -68,6 +68,18 @@ pub struct L1BatchHeader { pub fee_address: Address, } +impl L1BatchHeader { + pub fn to_unsealed_header(&self, fee_input: BatchFeeInput) -> UnsealedL1BatchHeader { + UnsealedL1BatchHeader { + number: self.number, + timestamp: self.timestamp, + protocol_version: self.protocol_version, + fee_address: self.fee_address, + fee_input, + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct UnsealedL1BatchHeader { pub number: L1BatchNumber, diff --git a/core/lib/utils/src/bytecode.rs b/core/lib/utils/src/bytecode.rs index 48bdb4330207..01cce5bc34d0 100644 --- a/core/lib/utils/src/bytecode.rs +++ b/core/lib/utils/src/bytecode.rs @@ -1,5 +1,6 @@ // FIXME: move to basic_types? +use zk_evm::k256::sha2::{Digest, Sha256}; use zksync_basic_types::H256; use crate::bytes_to_chunks; @@ -40,6 +41,7 @@ pub fn validate_bytecode(code: &[u8]) -> Result<(), InvalidBytecodeError> { Ok(()) } +/// Hashes the provided EraVM bytecode. pub fn hash_bytecode(code: &[u8]) -> H256 { let chunked_code = bytes_to_chunks(code); let hash = zk_evm::zkevm_opcode_defs::utils::bytecode_to_code_hash(&chunked_code) @@ -55,3 +57,62 @@ pub fn bytecode_len_in_words(bytecodehash: &H256) -> u16 { pub fn bytecode_len_in_bytes(bytecodehash: H256) -> usize { bytecode_len_in_words(&bytecodehash) as usize * 32 } + +/// Bytecode marker encoded in the first byte of the bytecode hash. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[repr(u8)] +pub enum BytecodeMarker { + /// EraVM bytecode marker (1). + EraVm = 1, + /// EVM bytecode marker (2). + Evm = 2, +} + +impl BytecodeMarker { + /// Parses a marker from the bytecode hash. + pub fn new(bytecode_hash: H256) -> Option { + Some(match bytecode_hash.as_bytes()[0] { + val if val == Self::EraVm as u8 => Self::EraVm, + val if val == Self::Evm as u8 => Self::Evm, + _ => return None, + }) + } +} + +/// Hashes the provided EVM bytecode. The bytecode must be padded to an odd number of 32-byte words; +/// bytecodes stored in the known codes storage satisfy this requirement automatically. +pub fn hash_evm_bytecode(bytecode: &[u8]) -> H256 { + validate_bytecode(bytecode).expect("invalid EVM bytecode"); + + let mut hasher = Sha256::new(); + let len = bytecode.len() as u16; + hasher.update(bytecode); + let result = hasher.finalize(); + + let mut output = [0u8; 32]; + output[..].copy_from_slice(result.as_slice()); + output[0] = BytecodeMarker::Evm as u8; + output[1] = 0; + output[2..4].copy_from_slice(&len.to_be_bytes()); + + H256(output) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn bytecode_markers_are_valid() { + let bytecode_hash = hash_bytecode(&[0; 32]); + assert_eq!( + BytecodeMarker::new(bytecode_hash), + Some(BytecodeMarker::EraVm) + ); + let bytecode_hash = hash_evm_bytecode(&[0; 32]); + assert_eq!( + BytecodeMarker::new(bytecode_hash), + Some(BytecodeMarker::Evm) + ); + } +} diff --git a/core/lib/utils/src/env.rs b/core/lib/utils/src/env.rs index 5ae07caf1486..8f4aa1da9400 100644 --- a/core/lib/utils/src/env.rs +++ b/core/lib/utils/src/env.rs @@ -19,8 +19,8 @@ pub enum Workspace<'a> { Core(&'a Path), /// `prover` folder. Prover(&'a Path), - /// `toolbox` folder. - Toolbox(&'a Path), + /// ZK Stack CLI folder. + ZkStackCli(&'a Path), } impl Workspace<'static> { @@ -48,7 +48,7 @@ impl Workspace<'static> { impl<'a> Workspace<'a> { const PROVER_DIRECTORY_NAME: &'static str = "prover"; - const TOOLBOX_DIRECTORY_NAME: &'static str = "zk_toolbox"; + const ZKSTACK_CLI_DIRECTORY_NAME: &'static str = "zkstack_cli"; /// Returns the path of the core workspace. /// For `Workspace::None`, considers the current directory to represent core workspace. @@ -56,7 +56,7 @@ impl<'a> Workspace<'a> { match self { Self::None => PathBuf::from("."), Self::Core(path) => path.into(), - Self::Prover(path) | Self::Toolbox(path) => path.parent().unwrap().into(), + Self::Prover(path) | Self::ZkStackCli(path) => path.parent().unwrap().into(), } } @@ -68,11 +68,11 @@ impl<'a> Workspace<'a> { } } - /// Returns the path of the `zk_toolbox`` workspace. - pub fn toolbox(self) -> PathBuf { + /// Returns the path of the ZK Stack CLI workspace. + pub fn zkstack_cli(self) -> PathBuf { match self { - Self::Toolbox(path) => path.into(), - _ => self.core().join(Self::TOOLBOX_DIRECTORY_NAME), + Self::ZkStackCli(path) => path.into(), + _ => self.core().join(Self::ZKSTACK_CLI_DIRECTORY_NAME), } } } @@ -81,8 +81,8 @@ impl<'a> From<&'a Path> for Workspace<'a> { fn from(path: &'a Path) -> Self { if path.ends_with(Self::PROVER_DIRECTORY_NAME) { Self::Prover(path) - } else if path.ends_with(Self::TOOLBOX_DIRECTORY_NAME) { - Self::Toolbox(path) + } else if path.ends_with(Self::ZKSTACK_CLI_DIRECTORY_NAME) { + Self::ZkStackCli(path) } else { Self::Core(path) } @@ -154,16 +154,16 @@ mod tests { let workspace = Workspace::locate(); assert_matches!(workspace, Workspace::Core(_)); let core_path = workspace.core(); - // Check if prover and toolbox directories exist. + // Check if prover and ZK Stack CLI directories exist. assert!(workspace.prover().exists()); assert_matches!( Workspace::from(workspace.prover().as_path()), Workspace::Prover(_) ); - assert!(workspace.toolbox().exists()); + assert!(workspace.zkstack_cli().exists()); assert_matches!( - Workspace::from(workspace.toolbox().as_path()), - Workspace::Toolbox(_) + Workspace::from(workspace.zkstack_cli().as_path()), + Workspace::ZkStackCli(_) ); // Prover. @@ -181,17 +181,17 @@ mod tests { Workspace::from(workspace.core().as_path()), Workspace::Core(_) ); - assert!(workspace.toolbox().exists()); + assert!(workspace.zkstack_cli().exists()); assert_matches!( - Workspace::from(workspace.toolbox().as_path()), - Workspace::Toolbox(_) + Workspace::from(workspace.zkstack_cli().as_path()), + Workspace::ZkStackCli(_) ); - // Toolbox. - std::env::set_current_dir(workspace.toolbox()).unwrap(); + // ZK Stack CLI + std::env::set_current_dir(workspace.zkstack_cli()).unwrap(); let workspace_path = locate_workspace_inner().unwrap(); let workspace = Workspace::from(workspace_path.as_path()); - assert_matches!(workspace, Workspace::Toolbox(_)); + assert_matches!(workspace, Workspace::ZkStackCli(_)); assert_eq!(workspace.core(), core_path); assert_matches!( Workspace::from(workspace.core().as_path()), diff --git a/core/lib/vm_interface/src/types/inputs/l1_batch_env.rs b/core/lib/vm_interface/src/types/inputs/l1_batch_env.rs index dbc942476170..0011f0b138b5 100644 --- a/core/lib/vm_interface/src/types/inputs/l1_batch_env.rs +++ b/core/lib/vm_interface/src/types/inputs/l1_batch_env.rs @@ -1,5 +1,8 @@ use serde::{Deserialize, Serialize}; -use zksync_types::{fee_model::BatchFeeInput, Address, L1BatchNumber, H256}; +use zksync_types::{ + block::UnsealedL1BatchHeader, fee_model::BatchFeeInput, Address, L1BatchNumber, + ProtocolVersionId, H256, +}; use super::L2BlockEnv; @@ -21,3 +24,18 @@ pub struct L1BatchEnv { pub enforced_base_fee: Option, pub first_l2_block: L2BlockEnv, } + +impl L1BatchEnv { + pub fn into_unsealed_header( + self, + protocol_version: Option, + ) -> UnsealedL1BatchHeader { + UnsealedL1BatchHeader { + number: self.number, + timestamp: self.timestamp, + protocol_version, + fee_address: self.fee_account, + fee_input: self.fee_input, + } + } +} diff --git a/core/node/api_server/Cargo.toml b/core/node/api_server/Cargo.toml index d0723a9d23e7..067b9b3e3722 100644 --- a/core/node/api_server/Cargo.toml +++ b/core/node/api_server/Cargo.toml @@ -61,4 +61,5 @@ zksync_node_genesis.workspace = true zksync_node_test_utils.workspace = true assert_matches.workspace = true +const-decoder.workspace = true test-casing.workspace = true diff --git a/core/node/api_server/src/testonly.rs b/core/node/api_server/src/testonly.rs index 43c7beb316ca..13e5ecc08ead 100644 --- a/core/node/api_server/src/testonly.rs +++ b/core/node/api_server/src/testonly.rs @@ -2,6 +2,7 @@ use std::{collections::HashMap, iter}; +use const_decoder::Decoder; use zk_evm_1_5_0::zkevm_opcode_defs::decoding::{EncodingModeProduction, VmEncodingMode}; use zksync_contracts::{ eth_contract, get_loadnext_contract, load_contract, read_bytecode, @@ -26,6 +27,30 @@ use zksync_types::{ }; use zksync_utils::{address_to_u256, u256_to_h256}; +pub(crate) const RAW_EVM_BYTECODE: &[u8] = &const_decoder::decode!( + Decoder::Hex, + b"00000000000000000000000000000000000000000000000000000000000001266080604052348015\ + 600e575f80fd5b50600436106030575f3560e01c8063816898ff146034578063fb5343f314604c57\ + 5b5f80fd5b604a60048036038101906046919060a6565b6066565b005b6052606f565b604051605d\ + 919060d9565b60405180910390f35b805f8190555050565b5f5481565b5f80fd5b5f819050919050\ + 565b6088816078565b81146091575f80fd5b50565b5f8135905060a0816081565b92915050565b5f\ + 6020828403121560b85760b76074565b5b5f60c3848285016094565b91505092915050565b60d381\ + 6078565b82525050565b5f60208201905060ea5f83018460cc565b9291505056fea2646970667358\ + 221220caca1247066da378f2ec77c310f2ae51576272367b4fa11cc4350af4e9ce4d0964736f6c63\ + 4300081a00330000000000000000000000000000000000000000000000000000" +); +pub(crate) const PROCESSED_EVM_BYTECODE: &[u8] = &const_decoder::decode!( + Decoder::Hex, + b"6080604052348015600e575f80fd5b50600436106030575f3560e01c8063816898ff146034578063\ + fb5343f314604c575b5f80fd5b604a60048036038101906046919060a6565b6066565b005b605260\ + 6f565b604051605d919060d9565b60405180910390f35b805f8190555050565b5f5481565b5f80fd\ + 5b5f819050919050565b6088816078565b81146091575f80fd5b50565b5f8135905060a081608156\ + 5b92915050565b5f6020828403121560b85760b76074565b5b5f60c3848285016094565b91505092\ + 915050565b60d3816078565b82525050565b5f60208201905060ea5f83018460cc565b9291505056\ + fea2646970667358221220caca1247066da378f2ec77c310f2ae51576272367b4fa11cc4350af4e9\ + ce4d0964736f6c634300081a0033" +); + const EXPENSIVE_CONTRACT_PATH: &str = "etc/contracts-test-data/artifacts-zk/contracts/expensive/expensive.sol/Expensive.json"; const PRECOMPILES_CONTRACT_PATH: &str = diff --git a/core/node/api_server/src/utils.rs b/core/node/api_server/src/utils.rs index 6769e773dc77..c7a1134682bf 100644 --- a/core/node/api_server/src/utils.rs +++ b/core/node/api_server/src/utils.rs @@ -6,9 +6,33 @@ use std::{ time::{Duration, Instant}, }; +use anyhow::Context; use zksync_dal::{Connection, Core, DalError}; +use zksync_multivm::circuit_sequencer_api_latest::boojum::ethereum_types::U256; use zksync_web3_decl::error::Web3Error; +pub(crate) fn prepare_evm_bytecode(raw: &[u8]) -> anyhow::Result> { + // EVM bytecodes are prefixed with a big-endian `U256` bytecode length. + let bytecode_len_bytes = raw.get(..32).context("length < 32")?; + let bytecode_len = U256::from_big_endian(bytecode_len_bytes); + let bytecode_len: usize = bytecode_len + .try_into() + .map_err(|_| anyhow::anyhow!("length ({bytecode_len}) overflow"))?; + let bytecode = raw.get(32..(32 + bytecode_len)).with_context(|| { + format!( + "prefixed length ({bytecode_len}) exceeds real length ({})", + raw.len() - 32 + ) + })?; + // Since slicing above succeeded, this one is safe. + let padding = &raw[(32 + bytecode_len)..]; + anyhow::ensure!( + padding.iter().all(|&b| b == 0), + "bytecode padding contains non-zero bytes" + ); + Ok(bytecode.to_vec()) +} + /// Opens a readonly transaction over the specified connection. pub(crate) async fn open_readonly_transaction<'r>( conn: &'r mut Connection<'_, Core>, @@ -66,3 +90,15 @@ macro_rules! report_filter { ReportFilter::new($interval, &LAST_TIMESTAMP) }}; } + +#[cfg(test)] +mod tests { + use super::*; + use crate::testonly::{PROCESSED_EVM_BYTECODE, RAW_EVM_BYTECODE}; + + #[test] + fn preparing_evm_bytecode() { + let prepared = prepare_evm_bytecode(RAW_EVM_BYTECODE).unwrap(); + assert_eq!(prepared, PROCESSED_EVM_BYTECODE); + } +} diff --git a/core/node/api_server/src/web3/namespaces/eth.rs b/core/node/api_server/src/web3/namespaces/eth.rs index 44362dd098e0..008c529ec638 100644 --- a/core/node/api_server/src/web3/namespaces/eth.rs +++ b/core/node/api_server/src/web3/namespaces/eth.rs @@ -12,7 +12,7 @@ use zksync_types::{ web3::{self, Bytes, SyncInfo, SyncState}, AccountTreeId, L2BlockNumber, StorageKey, H256, L2_BASE_TOKEN_ADDRESS, U256, }; -use zksync_utils::u256_to_h256; +use zksync_utils::{bytecode::BytecodeMarker, u256_to_h256}; use zksync_web3_decl::{ error::Web3Error, types::{Address, Block, Filter, FilterChanges, Log, U64}, @@ -21,7 +21,7 @@ use zksync_web3_decl::{ use crate::{ execution_sandbox::BlockArgs, tx_sender::BinarySearchKind, - utils::open_readonly_transaction, + utils::{open_readonly_transaction, prepare_evm_bytecode}, web3::{backend_jsonrpsee::MethodTracer, metrics::API_METRICS, state::RpcState, TypedFilter}, }; @@ -397,7 +397,22 @@ impl EthNamespace { .get_contract_code_unchecked(address, block_number) .await .map_err(DalError::generalize)?; - Ok(contract_code.unwrap_or_default().into()) + let Some(contract_code) = contract_code else { + return Ok(Bytes::default()); + }; + // Check if the bytecode is an EVM bytecode, and if so, pre-process it correspondingly. + let marker = BytecodeMarker::new(contract_code.bytecode_hash); + let prepared_bytecode = if marker == Some(BytecodeMarker::Evm) { + prepare_evm_bytecode(&contract_code.bytecode).with_context(|| { + format!( + "malformed EVM bytecode at address {address:?}, hash = {:?}", + contract_code.bytecode_hash + ) + })? + } else { + contract_code.bytecode + }; + Ok(prepared_bytecode.into()) } pub fn chain_id_impl(&self) -> U64 { diff --git a/core/node/api_server/src/web3/tests/mod.rs b/core/node/api_server/src/web3/tests/mod.rs index 632e263c6536..77b0b1824c75 100644 --- a/core/node/api_server/src/web3/tests/mod.rs +++ b/core/node/api_server/src/web3/tests/mod.rs @@ -31,17 +31,21 @@ use zksync_system_constants::{ }; use zksync_types::{ api, - block::{pack_block_info, L2BlockHeader}, + block::{pack_block_info, L2BlockHasher, L2BlockHeader}, get_nonce_key, l2::L2Tx, storage::get_code_key, + system_contracts::get_system_smart_contracts, tokens::{TokenInfo, TokenMetadata}, tx::IncludedTxLocation, utils::{storage_key_for_eth_balance, storage_key_for_standard_token_balance}, AccountTreeId, Address, L1BatchNumber, Nonce, ProtocolVersionId, StorageKey, StorageLog, H256, U256, U64, }; -use zksync_utils::u256_to_h256; +use zksync_utils::{ + bytecode::{hash_bytecode, hash_evm_bytecode}, + u256_to_h256, +}; use zksync_vm_executor::oneshot::MockOneshotExecutor; use zksync_web3_decl::{ client::{Client, DynClient, L2}, @@ -58,7 +62,10 @@ use zksync_web3_decl::{ }; use super::*; -use crate::web3::testonly::TestServerBuilder; +use crate::{ + testonly::{PROCESSED_EVM_BYTECODE, RAW_EVM_BYTECODE}, + web3::testonly::TestServerBuilder, +}; mod debug; mod filters; @@ -625,7 +632,7 @@ impl HttpTest for StorageAccessWithSnapshotRecovery { fn storage_initialization(&self) -> StorageInitialization { let address = Address::repeat_byte(1); let code_key = get_code_key(&address); - let code_hash = H256::repeat_byte(2); + let code_hash = hash_bytecode(&[0; 32]); let balance_key = storage_key_for_eth_balance(&address); let logs = vec![ StorageLog::new_write_log(code_key, code_hash), @@ -1102,3 +1109,122 @@ impl HttpTest for GenesisConfigTest { async fn tracing_genesis_config() { test_http_server(GenesisConfigTest).await; } + +#[derive(Debug)] +struct GetBytecodeTest; + +impl GetBytecodeTest { + async fn insert_evm_bytecode( + connection: &mut Connection<'_, Core>, + at_block: L2BlockNumber, + address: Address, + ) -> anyhow::Result<()> { + let evm_bytecode_hash = hash_evm_bytecode(RAW_EVM_BYTECODE); + let code_log = StorageLog::new_write_log(get_code_key(&address), evm_bytecode_hash); + connection + .storage_logs_dal() + .append_storage_logs(at_block, &[code_log]) + .await?; + + let factory_deps = HashMap::from([(evm_bytecode_hash, RAW_EVM_BYTECODE.to_vec())]); + connection + .factory_deps_dal() + .insert_factory_deps(at_block, &factory_deps) + .await?; + Ok(()) + } +} + +#[async_trait] +impl HttpTest for GetBytecodeTest { + async fn test( + &self, + client: &DynClient, + pool: &ConnectionPool, + ) -> anyhow::Result<()> { + let genesis_evm_address = Address::repeat_byte(1); + let mut connection = pool.connection().await?; + Self::insert_evm_bytecode(&mut connection, L2BlockNumber(0), genesis_evm_address).await?; + + for contract in get_system_smart_contracts(false) { + let bytecode = client + .get_code(*contract.account_id.address(), None) + .await?; + assert_eq!(bytecode.0, contract.bytecode); + } + + let bytecode = client.get_code(genesis_evm_address, None).await?; + assert_eq!(bytecode.0, PROCESSED_EVM_BYTECODE); + + let latest_block_variants = [ + api::BlockNumber::Pending, + api::BlockNumber::Latest, + api::BlockNumber::Committed, + ]; + let latest_block_variants = latest_block_variants.map(api::BlockIdVariant::BlockNumber); + + let genesis_block_variants = [ + api::BlockIdVariant::BlockNumber(api::BlockNumber::Earliest), + api::BlockIdVariant::BlockNumber(api::BlockNumber::Number(0.into())), + api::BlockIdVariant::BlockHashObject(api::BlockHashObject { + block_hash: L2BlockHasher::legacy_hash(L2BlockNumber(0)), + }), + ]; + for at_block in latest_block_variants + .into_iter() + .chain(genesis_block_variants) + { + println!("Testing {at_block:?} with genesis EVM code, latest block: 0"); + let bytecode = client.get_code(genesis_evm_address, Some(at_block)).await?; + assert_eq!(bytecode.0, PROCESSED_EVM_BYTECODE); + } + + // Create another block with an EVM bytecode. + let new_bytecode_address = Address::repeat_byte(2); + let mut connection = pool.connection().await?; + let block_header = store_l2_block(&mut connection, L2BlockNumber(1), &[]).await?; + Self::insert_evm_bytecode(&mut connection, L2BlockNumber(1), new_bytecode_address).await?; + + let bytecode = client.get_code(genesis_evm_address, None).await?; + assert_eq!(bytecode.0, PROCESSED_EVM_BYTECODE); + let bytecode = client.get_code(new_bytecode_address, None).await?; + assert_eq!(bytecode.0, PROCESSED_EVM_BYTECODE); + + let new_block_variants = [ + api::BlockIdVariant::BlockNumber(api::BlockNumber::Number(1.into())), + api::BlockIdVariant::BlockHashObject(api::BlockHashObject { + block_hash: block_header.hash, + }), + ]; + for at_block in latest_block_variants.into_iter().chain(new_block_variants) { + println!("Testing {at_block:?} with new EVM code, latest block: 1"); + let bytecode = client + .get_code(new_bytecode_address, Some(at_block)) + .await?; + assert_eq!(bytecode.0, PROCESSED_EVM_BYTECODE); + } + for at_block in genesis_block_variants { + println!("Testing {at_block:?} with new EVM code, latest block: 1"); + let bytecode = client + .get_code(new_bytecode_address, Some(at_block)) + .await?; + assert!(bytecode.0.is_empty()); + } + + for at_block in latest_block_variants + .into_iter() + .chain(new_block_variants) + .chain(genesis_block_variants) + { + println!("Testing {at_block:?} with genesis EVM code, latest block: 1"); + let bytecode = client.get_code(genesis_evm_address, Some(at_block)).await?; + assert_eq!(bytecode.0, PROCESSED_EVM_BYTECODE); + } + Ok(()) + } +} + +#[tokio::test] +async fn getting_bytecodes() { + test_http_server(GetBytecodeTest).await; +} diff --git a/core/node/consensus/src/en.rs b/core/node/consensus/src/en.rs index c358974fb0c1..518a7ebb29aa 100644 --- a/core/node/consensus/src/en.rs +++ b/core/node/consensus/src/en.rs @@ -4,7 +4,7 @@ use anyhow::Context as _; use zksync_concurrency::{ctx, error::Wrap as _, scope, time}; use zksync_consensus_executor::{self as executor, attestation}; use zksync_consensus_roles::{attester, validator}; -use zksync_consensus_storage::BlockStore; +use zksync_consensus_storage::{BlockStore, PersistentBlockStore as _}; use zksync_dal::consensus_dal; use zksync_node_sync::{fetcher::FetchedBlock, sync_action::ActionQueueSender, SyncState}; use zksync_types::L2BlockNumber; @@ -21,6 +21,10 @@ use crate::{ storage::{self, ConnectionPool}, }; +/// If less than TEMPORARY_FETCHER_THRESHOLD certificates are missing, +/// the temporary fetcher will stop fetching blocks. +pub(crate) const TEMPORARY_FETCHER_THRESHOLD: u64 = 10; + /// External node. pub(super) struct EN { pub(super) pool: ConnectionPool, @@ -120,6 +124,20 @@ impl EN { .wrap("Store::new()")?; s.spawn_bg(async { Ok(runner.run(ctx).await?) }); + // Run the temporary fetcher until the certificates are backfilled. + // Temporary fetcher should be removed once json RPC syncing is fully deprecated. + s.spawn_bg({ + let store = store.clone(); + async { + let store = store; + self.temporary_block_fetcher(ctx, &store).await?; + tracing::info!( + "temporary block fetcher finished, switching to p2p fetching only" + ); + Ok(()) + } + }); + let (block_store, runner) = BlockStore::new(ctx, Box::new(store.clone())) .await .wrap("BlockStore::new()")?; @@ -358,8 +376,42 @@ impl EN { } } + /// Fetches blocks from the main node directly, until the certificates + /// are backfilled. This allows for smooth transition from json RPC to p2p block syncing. + pub(crate) async fn temporary_block_fetcher( + &self, + ctx: &ctx::Ctx, + store: &Store, + ) -> ctx::Result<()> { + const MAX_CONCURRENT_REQUESTS: usize = 30; + scope::run!(ctx, |ctx, s| async { + let (send, mut recv) = ctx::channel::bounded(MAX_CONCURRENT_REQUESTS); + s.spawn(async { + let Some(mut next) = store.next_block(ctx).await? else { + return Ok(()); + }; + while store.persisted().borrow().next().0 + TEMPORARY_FETCHER_THRESHOLD < next.0 { + let n = L2BlockNumber(next.0.try_into().context("overflow")?); + self.sync_state.wait_for_main_node_block(ctx, n).await?; + send.send(ctx, s.spawn(self.fetch_block(ctx, n))).await?; + next = next.next(); + } + drop(send); + Ok(()) + }); + while let Ok(block) = recv.recv_or_disconnected(ctx).await? { + store + .queue_next_fetched_block(ctx, block.join(ctx).await?) + .await + .wrap("queue_next_fetched_block()")?; + } + Ok(()) + }) + .await + } + /// Fetches blocks from the main node in range `[cursor.next()..end)`. - pub(super) async fn fetch_blocks( + async fn fetch_blocks( &self, ctx: &ctx::Ctx, queue: &mut storage::PayloadQueue, @@ -373,7 +425,7 @@ impl EN { s.spawn(async { let send = send; while end.map_or(true, |end| next < end) { - let n = L2BlockNumber(next.0.try_into().unwrap()); + let n = L2BlockNumber(next.0.try_into().context("overflow")?); self.sync_state.wait_for_main_node_block(ctx, n).await?; send.send(ctx, s.spawn(self.fetch_block(ctx, n))).await?; next = next.next(); diff --git a/core/node/consensus/src/registry/tests.rs b/core/node/consensus/src/registry/tests.rs index 33392a7f206d..89afc20e1d57 100644 --- a/core/node/consensus/src/registry/tests.rs +++ b/core/node/consensus/src/registry/tests.rs @@ -80,7 +80,7 @@ async fn test_attester_committee() { .wrap("wait_for_batch_info()")?; // Read the attester committee using the vm. - let batch = attester::BatchNumber(node.last_batch().0.into()); + let batch = attester::BatchNumber(node.last_batch().0); assert_eq!( Some(committee), registry diff --git a/core/node/consensus/src/storage/store.rs b/core/node/consensus/src/storage/store.rs index ed83758ba9f0..7267d7e1c822 100644 --- a/core/node/consensus/src/storage/store.rs +++ b/core/node/consensus/src/storage/store.rs @@ -111,6 +111,30 @@ impl Store { async fn conn(&self, ctx: &ctx::Ctx) -> ctx::Result { self.pool.connection(ctx).await.wrap("connection") } + + /// Number of the next block to queue. + pub(crate) async fn next_block( + &self, + ctx: &ctx::Ctx, + ) -> ctx::OrCanceled> { + Ok(sync::lock(ctx, &self.block_payloads) + .await? + .as_ref() + .map(|p| p.next())) + } + + /// Queues the next block. + pub(crate) async fn queue_next_fetched_block( + &self, + ctx: &ctx::Ctx, + block: FetchedBlock, + ) -> ctx::Result<()> { + let mut payloads = sync::lock(ctx, &self.block_payloads).await?.into_async(); + if let Some(payloads) = &mut *payloads { + payloads.send(block).await.context("payloads.send()")?; + } + Ok(()) + } } impl PersistedBlockState { diff --git a/core/node/consensus/src/testonly.rs b/core/node/consensus/src/testonly.rs index 4538337109a4..4ebcf5c9a617 100644 --- a/core/node/consensus/src/testonly.rs +++ b/core/node/consensus/src/testonly.rs @@ -45,7 +45,10 @@ use zksync_types::{ }; use zksync_web3_decl::client::{Client, DynClient, L2}; -use crate::{en, storage::ConnectionPool}; +use crate::{ + en, + storage::{ConnectionPool, Store}, +}; /// Fake StateKeeper for tests. #[derive(Debug)] @@ -154,6 +157,7 @@ fn make_config( genesis_spec: Option, ) -> config::ConsensusConfig { config::ConsensusConfig { + port: Some(cfg.server_addr.port()), server_addr: *cfg.server_addr, public_addr: config::Host(cfg.public_addr.0.clone()), max_payload_size: usize::MAX, @@ -416,6 +420,40 @@ impl StateKeeper { .await } + pub async fn run_temporary_fetcher( + self, + ctx: &ctx::Ctx, + client: Box>, + ) -> ctx::Result<()> { + scope::run!(ctx, |ctx, s| async { + let payload_queue = self + .pool + .connection(ctx) + .await + .wrap("connection()")? + .new_payload_queue(ctx, self.actions_sender, self.sync_state.clone()) + .await + .wrap("new_payload_queue()")?; + let (store, runner) = Store::new( + ctx, + self.pool.clone(), + Some(payload_queue), + Some(client.clone()), + ) + .await + .wrap("Store::new()")?; + s.spawn_bg(async { Ok(runner.run(ctx).await?) }); + en::EN { + pool: self.pool.clone(), + client, + sync_state: self.sync_state.clone(), + } + .temporary_block_fetcher(ctx, &store) + .await + }) + .await + } + /// Runs consensus node for the external node. pub async fn run_consensus( self, diff --git a/core/node/consensus/src/tests/attestation.rs b/core/node/consensus/src/tests/attestation.rs index bd3886bd4c89..2701a986e9e9 100644 --- a/core/node/consensus/src/tests/attestation.rs +++ b/core/node/consensus/src/tests/attestation.rs @@ -79,7 +79,7 @@ async fn test_attestation_status_api(version: ProtocolVersionId) { let status = fetch_status().await?; assert_eq!( status.next_batch_to_attest, - attester::BatchNumber(first_batch.0.into()) + attester::BatchNumber(first_batch.0) ); tracing::info!("Insert a cert"); @@ -237,7 +237,7 @@ async fn test_multiple_attesters(version: ProtocolVersionId, pregenesis: bool) { } tracing::info!("Wait for the batches to be attested"); - let want_last = attester::BatchNumber(validator.last_sealed_batch().0.into()); + let want_last = attester::BatchNumber(validator.last_sealed_batch().0); validator_pool .wait_for_batch_certificates_and_verify(ctx, want_last, Some(registry_addr)) .await?; diff --git a/core/node/consensus/src/tests/mod.rs b/core/node/consensus/src/tests/mod.rs index 94fbcbb90d84..8da17cfba8ac 100644 --- a/core/node/consensus/src/tests/mod.rs +++ b/core/node/consensus/src/tests/mod.rs @@ -13,8 +13,10 @@ use zksync_consensus_storage::{BlockStore, PersistentBlockStore}; use zksync_dal::consensus_dal; use zksync_test_account::Account; use zksync_types::ProtocolVersionId; +use zksync_web3_decl::namespaces::EnNamespaceClient as _; use crate::{ + en::TEMPORARY_FETCHER_THRESHOLD, mn::run_main_node, storage::{ConnectionPool, Store}, testonly, @@ -665,6 +667,136 @@ async fn test_p2p_fetcher_backfill_certs( .unwrap(); } +// Test temporary fetcher fetching blocks if a lot of certs are missing. +#[test_casing(8, Product((FROM_SNAPSHOT,VERSIONS,PREGENESIS)))] +#[tokio::test] +async fn test_temporary_fetcher(from_snapshot: bool, version: ProtocolVersionId, pregenesis: bool) { + zksync_concurrency::testonly::abort_on_panic(); + let ctx = &ctx::test_root(&ctx::AffineClock::new(10.)); + let rng = &mut ctx.rng(); + // We force certs to be missing on EN by having 1 of the validators permanently offline. + // This way no blocks will be finalized at all, so no one will have certs. + let setup = Setup::new(rng, 2); + let validator_cfg = testonly::new_configs(rng, &setup, 0, pregenesis)[0].clone(); + let node_cfg = validator_cfg.new_fullnode(rng); + let account = &mut Account::random(); + + scope::run!(ctx, |ctx, s| async { + tracing::info!("Spawn validator."); + let validator_pool = ConnectionPool::test(from_snapshot, version).await; + let (mut validator, runner) = + testonly::StateKeeper::new(ctx, validator_pool.clone()).await?; + s.spawn_bg(runner.run(ctx)); + s.spawn_bg(run_main_node( + ctx, + validator_cfg.config.clone(), + validator_cfg.secrets.clone(), + validator_pool.clone(), + )); + // API server needs at least 1 L1 batch to start. + validator.seal_batch().await; + let client = validator.connect(ctx).await?; + + // Wait for the consensus to be initialized. + while ctx.wait(client.consensus_global_config()).await??.is_none() { + ctx.sleep(time::Duration::milliseconds(100)).await?; + } + + let node_pool = ConnectionPool::test(from_snapshot, version).await; + + tracing::info!("Run centralized fetcher, so that there is a lot of certs missing."); + scope::run!(ctx, |ctx, s| async { + let (node, runner) = testonly::StateKeeper::new(ctx, node_pool.clone()).await?; + s.spawn_bg(runner.run(ctx)); + s.spawn_bg(node.run_fetcher(ctx, client.clone())); + validator + .push_random_blocks(rng, account, TEMPORARY_FETCHER_THRESHOLD as usize + 1) + .await; + node_pool + .wait_for_payload(ctx, validator.last_block()) + .await?; + Ok(()) + }) + .await + .unwrap(); + + tracing::info!( + "Run p2p fetcher. Blocks should be fetched by the temporary fetcher anyway." + ); + scope::run!(ctx, |ctx, s| async { + let (node, runner) = testonly::StateKeeper::new(ctx, node_pool.clone()).await?; + s.spawn_bg(runner.run(ctx)); + s.spawn_bg(node.run_consensus(ctx, client.clone(), node_cfg.clone())); + validator.push_random_blocks(rng, account, 5).await; + node_pool + .wait_for_payload(ctx, validator.last_block()) + .await?; + Ok(()) + }) + .await + .unwrap(); + Ok(()) + }) + .await + .unwrap(); +} + +// Test that temporary fetcher terminates once enough blocks have certs. +#[test_casing(4, Product((FROM_SNAPSHOT,VERSIONS)))] +#[tokio::test] +async fn test_temporary_fetcher_termination(from_snapshot: bool, version: ProtocolVersionId) { + zksync_concurrency::testonly::abort_on_panic(); + let ctx = &ctx::test_root(&ctx::AffineClock::new(10.)); + let rng = &mut ctx.rng(); + let setup = Setup::new(rng, 1); + let pregenesis = true; + let validator_cfg = testonly::new_configs(rng, &setup, 0, pregenesis)[0].clone(); + let node_cfg = validator_cfg.new_fullnode(rng); + let account = &mut Account::random(); + + scope::run!(ctx, |ctx, s| async { + tracing::info!("Spawn validator."); + let validator_pool = ConnectionPool::test(from_snapshot, version).await; + let (mut validator, runner) = + testonly::StateKeeper::new(ctx, validator_pool.clone()).await?; + s.spawn_bg(runner.run(ctx)); + s.spawn_bg(run_main_node( + ctx, + validator_cfg.config.clone(), + validator_cfg.secrets.clone(), + validator_pool.clone(), + )); + // API server needs at least 1 L1 batch to start. + validator.seal_batch().await; + let client = validator.connect(ctx).await?; + + let node_pool = ConnectionPool::test(from_snapshot, version).await; + + // Run the EN so the consensus is initialized on EN and wait for it to sync. + scope::run!(ctx, |ctx, s| async { + let (node, runner) = testonly::StateKeeper::new(ctx, node_pool.clone()).await?; + s.spawn_bg(runner.run(ctx)); + s.spawn_bg(node.run_consensus(ctx, client.clone(), node_cfg.clone())); + validator.push_random_blocks(rng, account, 5).await; + node_pool + .wait_for_payload(ctx, validator.last_block()) + .await?; + Ok(()) + }) + .await + .unwrap(); + + // Run the temporary fetcher. It should terminate immediately, since EN is synced. + let (node, runner) = testonly::StateKeeper::new(ctx, node_pool.clone()).await?; + s.spawn_bg(runner.run(ctx)); + node.run_temporary_fetcher(ctx, client).await?; + + Ok(()) + }) + .await + .unwrap(); +} + #[test_casing(4, Product((VERSIONS,PREGENESIS)))] #[tokio::test] async fn test_with_pruning(version: ProtocolVersionId, pregenesis: bool) { diff --git a/core/node/genesis/src/lib.rs b/core/node/genesis/src/lib.rs index ba5e10dfb22c..3e4c0ee30b94 100644 --- a/core/node/genesis/src/lib.rs +++ b/core/node/genesis/src/lib.rs @@ -419,13 +419,7 @@ pub async fn create_genesis_l1_batch( .await?; transaction .blocks_dal() - .insert_l1_batch( - genesis_l1_batch_header.number, - genesis_l1_batch_header.timestamp, - genesis_l1_batch_header.protocol_version, - genesis_l1_batch_header.fee_address, - batch_fee_input, - ) + .insert_l1_batch(genesis_l1_batch_header.to_unsealed_header(batch_fee_input)) .await?; transaction .blocks_dal() diff --git a/core/node/node_sync/src/external_io.rs b/core/node/node_sync/src/external_io.rs index d4e7240da346..9148f9638684 100644 --- a/core/node/node_sync/src/external_io.rs +++ b/core/node/node_sync/src/external_io.rs @@ -15,6 +15,7 @@ use zksync_state_keeper::{ updates::UpdatesManager, }; use zksync_types::{ + block::UnsealedL1BatchHeader, protocol_upgrade::ProtocolUpgradeTx, protocol_version::{ProtocolSemanticVersion, VersionPatch}, L1BatchNumber, L2BlockNumber, L2ChainId, ProtocolVersionId, Transaction, H256, @@ -200,6 +201,14 @@ impl StateKeeperIO for ExternalIO { cursor.l1_batch ) })?; + storage + .blocks_dal() + .ensure_unsealed_l1_batch_exists( + l1_batch_env + .clone() + .into_unsealed_header(Some(system_env.version)), + ) + .await?; let data = load_pending_batch(&mut storage, system_env, l1_batch_env) .await .with_context(|| { @@ -241,13 +250,13 @@ impl StateKeeperIO for ExternalIO { .connection() .await? .blocks_dal() - .insert_l1_batch( - cursor.l1_batch, - params.first_l2_block.timestamp, - None, - params.operator_address, - params.fee_input, - ) + .insert_l1_batch(UnsealedL1BatchHeader { + number: cursor.l1_batch, + timestamp: params.first_l2_block.timestamp, + protocol_version: None, + fee_address: params.operator_address, + fee_input: params.fee_input, + }) .await?; return Ok(Some(params)); } diff --git a/core/node/state_keeper/src/io/mempool.rs b/core/node/state_keeper/src/io/mempool.rs index f771a2dda4ce..5a3fb8e4c4fc 100644 --- a/core/node/state_keeper/src/io/mempool.rs +++ b/core/node/state_keeper/src/io/mempool.rs @@ -14,8 +14,8 @@ use zksync_mempool::L2TxFilter; use zksync_multivm::{interface::Halt, utils::derive_base_fee_and_gas_per_pubdata}; use zksync_node_fee_model::BatchFeeModelInputProvider; use zksync_types::{ - protocol_upgrade::ProtocolUpgradeTx, utils::display_timestamp, Address, L1BatchNumber, - L2BlockNumber, L2ChainId, ProtocolVersionId, Transaction, H256, U256, + block::UnsealedL1BatchHeader, protocol_upgrade::ProtocolUpgradeTx, utils::display_timestamp, + Address, L1BatchNumber, L2BlockNumber, L2ChainId, ProtocolVersionId, Transaction, H256, U256, }; // TODO (SMA-1206): use seconds instead of milliseconds. use zksync_utils::time::millis_since_epoch; @@ -133,6 +133,15 @@ impl StateKeeperIO for MempoolIO { gas_per_pubdata: gas_per_pubdata as u32, }; + storage + .blocks_dal() + .ensure_unsealed_l1_batch_exists( + l1_batch_env + .clone() + .into_unsealed_header(Some(system_env.version)), + ) + .await?; + Ok(( cursor, Some(PendingBatchData { @@ -219,13 +228,13 @@ impl StateKeeperIO for MempoolIO { .connection() .await? .blocks_dal() - .insert_l1_batch( - cursor.l1_batch, + .insert_l1_batch(UnsealedL1BatchHeader { + number: cursor.l1_batch, timestamp, - Some(protocol_version), - self.fee_account, - self.filter.fee_input, - ) + protocol_version: Some(protocol_version), + fee_address: self.fee_account, + fee_input: self.filter.fee_input, + }) .await?; return Ok(Some(L1BatchParams { diff --git a/core/node/state_keeper/src/io/persistence.rs b/core/node/state_keeper/src/io/persistence.rs index 16275ec672df..3e11285e11f1 100644 --- a/core/node/state_keeper/src/io/persistence.rs +++ b/core/node/state_keeper/src/io/persistence.rs @@ -456,13 +456,7 @@ mod tests { .await .unwrap() .blocks_dal() - .insert_l1_batch( - l1_batch_env.number, - l1_batch_env.timestamp, - None, - l1_batch_env.fee_account, - l1_batch_env.fee_input, - ) + .insert_l1_batch(l1_batch_env.into_unsealed_header(None)) .await .unwrap(); diff --git a/core/node/state_keeper/src/io/tests/mod.rs b/core/node/state_keeper/src/io/tests/mod.rs index cd60bc68b36a..566eebf7ab72 100644 --- a/core/node/state_keeper/src/io/tests/mod.rs +++ b/core/node/state_keeper/src/io/tests/mod.rs @@ -606,3 +606,37 @@ async fn continue_unsealed_batch_on_restart(commitment_mode: L1BatchCommitmentMo assert_eq!(old_l1_batch_params, new_l1_batch_params); } + +#[test_casing(2, COMMITMENT_MODES)] +#[tokio::test] +async fn insert_unsealed_batch_on_init(commitment_mode: L1BatchCommitmentMode) { + let connection_pool = ConnectionPool::::test_pool().await; + let mut tester = Tester::new(commitment_mode); + tester.genesis(&connection_pool).await; + let fee_input = BatchFeeInput::pubdata_independent(55, 555, 5555); + let tx_result = tester + .insert_l2_block(&connection_pool, 1, 5, fee_input) + .await; + tester + .insert_sealed_batch(&connection_pool, 1, &[tx_result]) + .await; + // Pre-insert L2 block without its unsealed L1 batch counterpart + tester.set_timestamp(2); + tester + .insert_l2_block(&connection_pool, 2, 5, fee_input) + .await; + + let (mut mempool, _) = tester.create_test_mempool_io(connection_pool.clone()).await; + // Initialization is supposed to recognize that the current L1 batch is not present in the DB and + // insert it itself. + let (cursor, _) = mempool.initialize().await.unwrap(); + + // Make sure we are able to fetch the newly inserted batch's params + let l1_batch_params = mempool + .wait_for_new_batch_params(&cursor, Duration::from_secs(10)) + .await + .unwrap() + .expect("no batch params generated"); + assert_eq!(l1_batch_params.fee_input, fee_input); + assert_eq!(l1_batch_params.first_l2_block.timestamp, 2); +} diff --git a/core/tests/recovery-test/src/index.ts b/core/tests/recovery-test/src/index.ts index 462404af6065..8567be6d6d30 100644 --- a/core/tests/recovery-test/src/index.ts +++ b/core/tests/recovery-test/src/index.ts @@ -84,9 +84,9 @@ export async function getExternalNodeHealth(url: string) { } } -export async function dropNodeData(env: { [key: string]: string }, useZkSupervisor?: boolean, chain?: string) { - if (useZkSupervisor) { - let cmd = 'zk_inception external-node init'; +export async function dropNodeData(env: { [key: string]: string }, useZkStack?: boolean, chain?: string) { + if (useZkStack) { + let cmd = 'zkstack external-node init'; cmd += chain ? ` --chain ${chain}` : ''; await executeNodeCommand(env, cmd); } else { @@ -176,7 +176,7 @@ export class NodeProcess { logsFile: FileHandle | string, pathToHome: string, components: NodeComponents = NodeComponents.STANDARD, - useZkInception?: boolean, + useZkStack?: boolean, chain?: string ) { const logs = typeof logsFile === 'string' ? await fs.open(logsFile, 'a') : logsFile; @@ -186,7 +186,7 @@ export class NodeProcess { stdio: ['ignore', logs.fd, logs.fd], cwd: pathToHome, env, - useZkInception, + useZkStack, chain }); diff --git a/core/tests/recovery-test/src/utils.ts b/core/tests/recovery-test/src/utils.ts index 98c6b6d4405c..c60f5603f17d 100644 --- a/core/tests/recovery-test/src/utils.ts +++ b/core/tests/recovery-test/src/utils.ts @@ -48,19 +48,19 @@ export function runExternalNodeInBackground({ stdio, cwd, env, - useZkInception, + useZkStack, chain }: { components?: string[]; stdio: any; cwd?: Parameters[0]['cwd']; env?: Parameters[0]['env']; - useZkInception?: boolean; + useZkStack?: boolean; chain?: string; }): ChildProcessWithoutNullStreams { let command = ''; - if (useZkInception) { - command = 'zk_inception external-node run'; + if (useZkStack) { + command = 'zkstack external-node run'; command += chain ? ` --chain ${chain}` : ''; } else { command = 'zk external-node --'; diff --git a/core/tests/recovery-test/tests/snapshot-recovery.test.ts b/core/tests/recovery-test/tests/snapshot-recovery.test.ts index cadf146c5226..eca0da78d782 100644 --- a/core/tests/recovery-test/tests/snapshot-recovery.test.ts +++ b/core/tests/recovery-test/tests/snapshot-recovery.test.ts @@ -458,10 +458,10 @@ async function decompressGzip(filePath: string): Promise { }); } -async function createSnapshot(zkSupervisor: boolean) { +async function createSnapshot(useZkStack: boolean) { let command = ''; - if (zkSupervisor) { - command = `zk_supervisor snapshot create`; + if (useZkStack) { + command = `zkstack dev snapshot create`; command += ` --chain ${fileConfig.chain}`; } else { command = `zk run snapshots-creator`; diff --git a/core/tests/revert-test/tests/utils.ts b/core/tests/revert-test/tests/utils.ts index ea8a45b97c37..fe5cb40799a4 100644 --- a/core/tests/revert-test/tests/utils.ts +++ b/core/tests/revert-test/tests/utils.ts @@ -51,19 +51,19 @@ export function runServerInBackground({ stdio, cwd, env, - useZkInception, + useZkStack, chain }: { components?: string[]; stdio: any; cwd?: Parameters[0]['cwd']; env?: Parameters[0]['env']; - useZkInception?: boolean; + useZkStack?: boolean; chain?: string; }): ChildProcessWithoutNullStreams { let command = ''; - if (useZkInception) { - command = 'zk_inception server'; + if (useZkStack) { + command = 'zkstack server'; if (chain) { command += ` --chain ${chain}`; } @@ -78,19 +78,19 @@ export function runExternalNodeInBackground({ stdio, cwd, env, - useZkInception, + useZkStack, chain }: { components?: string[]; stdio: any; cwd?: Parameters[0]['cwd']; env?: Parameters[0]['env']; - useZkInception?: boolean; + useZkStack?: boolean; chain?: string; }): ChildProcessWithoutNullStreams { let command = ''; - if (useZkInception) { - command = 'zk_inception external-node run'; + if (useZkStack) { + command = 'zkstack external-node run'; command += chain ? ` --chain ${chain}` : ''; } else { command = 'zk external-node'; @@ -334,7 +334,7 @@ export class NodeSpawner { stdio: ['ignore', logs, logs], cwd: pathToHome, env: env, - useZkInception: fileConfig.loadFromFile, + useZkStack: fileConfig.loadFromFile, chain: fileConfig.chain }); @@ -362,7 +362,7 @@ export class NodeSpawner { stdio: ['ignore', logs, logs], cwd: pathToHome, env, - useZkInception: fileConfig.loadFromFile, + useZkStack: fileConfig.loadFromFile, chain: fileConfig.chain }); diff --git a/core/tests/ts-integration/src/utils.ts b/core/tests/ts-integration/src/utils.ts index 128d0be57d00..bb6fa93757ee 100644 --- a/core/tests/ts-integration/src/utils.ts +++ b/core/tests/ts-integration/src/utils.ts @@ -20,21 +20,21 @@ export function runServerInBackground({ stdio, cwd, env, - useZkInception, + useZkStack, chain }: { components?: string[]; stdio: any; cwd?: ProcessEnvOptions['cwd']; env?: ProcessEnvOptions['env']; - useZkInception?: boolean; + useZkStack?: boolean; newL1GasPrice?: string; newPubdataPrice?: string; chain?: string; }): ChildProcessWithoutNullStreams { let command = ''; - if (useZkInception) { - command = 'zk_inception server'; + if (useZkStack) { + command = 'zkstack server'; if (chain) { command += ` --chain ${chain}`; } @@ -167,7 +167,7 @@ export class NodeSpawner { stdio: ['ignore', logs, logs], cwd: pathToHome, env: env, - useZkInception: fileConfig.loadFromFile, + useZkStack: fileConfig.loadFromFile, chain: fileConfig.chain }); diff --git a/core/tests/ts-integration/tests/fees.test.ts b/core/tests/ts-integration/tests/fees.test.ts index c41f5943efb5..e99d3b67911b 100644 --- a/core/tests/ts-integration/tests/fees.test.ts +++ b/core/tests/ts-integration/tests/fees.test.ts @@ -278,7 +278,6 @@ testFees('Test fees', function () { }); afterAll(async () => { - await testMaster.deinitialize(); await mainNode.killAndWaitForShutdown(); // Returning the pubdata price to the default one @@ -287,6 +286,7 @@ testFees('Test fees', function () { deleteInternalEnforcedL1GasPrice(pathToHome, fileConfig); deleteInternalEnforcedPubdataPrice(pathToHome, fileConfig); mainNode = await mainNodeSpawner.spawnMainNode(); + await testMaster.deinitialize(); __ZKSYNC_TEST_CONTEXT_OWNER__.setL2NodePid(mainNode.proc.pid!); }); }); diff --git a/core/tests/upgrade-test/tests/upgrade.test.ts b/core/tests/upgrade-test/tests/upgrade.test.ts index 8a596747b454..4065480b121b 100644 --- a/core/tests/upgrade-test/tests/upgrade.test.ts +++ b/core/tests/upgrade-test/tests/upgrade.test.ts @@ -160,7 +160,7 @@ describe('Upgrade test', function () { components: serverComponents, stdio: ['ignore', logs, logs], cwd: pathToHome, - useZkInception: fileConfig.loadFromFile, + useZkStack: fileConfig.loadFromFile, chain: fileConfig.chain }); // Server may need some time to recompile if it's a cold run, so wait for it. @@ -377,7 +377,7 @@ describe('Upgrade test', function () { components: serverComponents, stdio: ['ignore', logs, logs], cwd: pathToHome, - useZkInception: fileConfig.loadFromFile, + useZkStack: fileConfig.loadFromFile, chain: fileConfig.chain }); await utils.sleep(10); diff --git a/core/tests/upgrade-test/tests/utils.ts b/core/tests/upgrade-test/tests/utils.ts index 80abaad41b1e..2972f8411f5f 100644 --- a/core/tests/upgrade-test/tests/utils.ts +++ b/core/tests/upgrade-test/tests/utils.ts @@ -7,19 +7,19 @@ export function runServerInBackground({ components, stdio, cwd, - useZkInception, + useZkStack, chain }: { components?: string[]; stdio: any; cwd?: Parameters[0]['cwd']; - useZkInception?: boolean; + useZkStack?: boolean; chain?: string; }) { let command = ''; - if (useZkInception) { - command = 'zk_inception server'; + if (useZkStack) { + command = 'zkstack server'; command += chain ? ` --chain ${chain}` : ''; } else { command = 'cd $ZKSYNC_HOME && cargo run --bin zksync_server --release --'; @@ -71,8 +71,8 @@ export interface Contracts { stateTransitonManager: any; } -export function initContracts(pathToHome: string, zkToolbox: boolean): Contracts { - if (zkToolbox) { +export function initContracts(pathToHome: string, zkStack: boolean): Contracts { + if (zkStack) { const CONTRACTS_FOLDER = `${pathToHome}/contracts`; return { l1DefaultUpgradeAbi: new ethers.Interface( diff --git a/docker/Makefile b/docker/Makefile index d7dc80c6f348..4e0ca51f904e 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -66,8 +66,8 @@ prepare-contracts: check-tools check-contracts @cd ../ && \ export ZKSYNC_HOME=$$(pwd) && \ export PATH=$$PATH:$${ZKSYNC_HOME}/bin:$${ZKSYNC_HOME}/zkstack_cli/zkstackup && \ - zkt || true && \ - zk_supervisor contracts && \ + zkstackup -g --local || true && \ + zkstack dev contracts && \ mkdir -p contracts/l1-contracts/artifacts # Download setup-key diff --git a/docker/prover-autoscaler/Dockerfile b/docker/prover-autoscaler/Dockerfile new file mode 100644 index 000000000000..246e8099ffd3 --- /dev/null +++ b/docker/prover-autoscaler/Dockerfile @@ -0,0 +1,25 @@ +FROM ghcr.io/matter-labs/zksync-build-base:latest AS builder + +ARG DEBIAN_FRONTEND=noninteractive + +# set of args for use of sccache +ARG SCCACHE_GCS_BUCKET="" +ARG SCCACHE_GCS_SERVICE_ACCOUNT="" +ARG SCCACHE_GCS_RW_MODE="" +ARG RUSTC_WRAPPER="" + +ENV SCCACHE_GCS_BUCKET=${SCCACHE_GCS_BUCKET} +ENV SCCACHE_GCS_SERVICE_ACCOUNT=${SCCACHE_GCS_SERVICE_ACCOUNT} +ENV SCCACHE_GCS_RW_MODE=${SCCACHE_GCS_RW_MODE} +ENV RUSTC_WRAPPER=${RUSTC_WRAPPER} + +WORKDIR /usr/src/zksync +COPY . . + +RUN cd prover && cargo build --release --bin zksync_prover_autoscaler + +FROM ghcr.io/matter-labs/zksync-runtime-base:latest + +COPY --from=builder /usr/src/zksync/prover/target/release/zksync_prover_autoscaler /usr/bin/ + +ENTRYPOINT ["/usr/bin/zksync_prover_autoscaler"] diff --git a/docs/specs/README.md b/docs/specs/README.md index 1f163bf7845f..d0b087ae93e3 100644 --- a/docs/specs/README.md +++ b/docs/specs/README.md @@ -33,4 +33,4 @@ 1. [ZK Chain ecosystem](./zk_chains/README.md) - [Overview](./zk_chains/overview.md) - [Shared Bridge](./zk_chains/shared_bridge.md) - - [Hyperbridges](./zk_chains/hyperbridges.md) + - [Interop](./zk_chains/interop.md) diff --git a/docs/specs/zk_chains/README.md b/docs/specs/zk_chains/README.md index 4de575899dd1..ce0a7c311a2f 100644 --- a/docs/specs/zk_chains/README.md +++ b/docs/specs/zk_chains/README.md @@ -2,4 +2,4 @@ - [Overview](./overview.md) - [Shared Bridge](./shared_bridge.md) -- [Hyperbridges](./hyperbridges.md) +- [Interop](./interop.md) diff --git a/docs/specs/zk_chains/gateway.md b/docs/specs/zk_chains/gateway.md new file mode 100644 index 000000000000..f4ee68e242e6 --- /dev/null +++ b/docs/specs/zk_chains/gateway.md @@ -0,0 +1 @@ +# Gateway diff --git a/docs/specs/zk_chains/hyperbridges.md b/docs/specs/zk_chains/hyperbridges.md deleted file mode 100644 index 614fe61427e3..000000000000 --- a/docs/specs/zk_chains/hyperbridges.md +++ /dev/null @@ -1,41 +0,0 @@ -# Hyperbridges - -## Introduction - -In the Shared bridge document we described how the L1 smart contracts work to support multiple chains, and we emphasized -that the core feature is hyperbridging, but we did not outline the hyperbridges themselves. This is because hyperbridges -are mostly L2 contracts. In this document we describe what hyperbridges are, and specify the necessary infrastructure. - -### Hyperbridge description - -Hyperbridges are trustless and cheap general native bridges between ZK Chains, allowing cross-chain function calls. -Trustlessness is achieved by relying on the main ZK Chain bridge to send a compressed message to L1, which is then sent -to and expanded on the destination ZK Chain. - -Technically they are a system of smart contracts that build on top of the enshrined L1<>L2 validating bridges, and can -interpret messages sent from L2 to L2 by verifying Merkle proofs. They are built alongside the protocol, they can -transfer the native asset of the ecosystem, and they can be used for asynchronous function calls between ZK Chains. - -![Hyperbridges](./img/hyperbridges.png) - -The trustless nature of hyperbridges allows the ecosystem to resemble a single VM. To illustrate imagine a new ZK Chain -joining the ecosystem. We will want ether/Dai/etc. to be accessible on this ZK Chain. This can be done automatically. -There will be a central erc20 deployer contract in the ecosystem, which will deploy the new ERC20 contract via the -hyperbridge. After the contract is deployed it will be able to interact other Dai contracts in the ecosystem. - -### High Level design - -![Hyperbridging](./img/hyperbridging.png) - -### L1 - -For the larger context see the [Shared Bridge](./shared_bridge.md) document, here we will focus on - -- HyperMailbox (part of Bridgehub). Contains the Hyperroot, root of Merkle tree of Hyperlogs. Hyperlogs are the L2->L1 - SysLogs that record the sent hyperbridge messages from the L2s. - -### L2 Contracts - -- Outbox system contract. It collects the hyperbridge txs into the hyperlog of the ZK Chain. -- Inbox system contract. This is where the hyperroot is imported and sent to L1 for settlement. Merkle proofs are - verified here, tx calls are started from here, nullifiers are stored here (add epochs later) diff --git a/docs/specs/zk_chains/interop.md b/docs/specs/zk_chains/interop.md new file mode 100644 index 000000000000..947742909b8d --- /dev/null +++ b/docs/specs/zk_chains/interop.md @@ -0,0 +1,49 @@ +# Interop + +## Introduction + +In the Shared bridge document we described how the L1 smart contracts work to support multiple chains, and we emphasized +that the core feature is interop. Interop happens via the same L1->L2 interface as described in the L1SharedBridge doc. +There is (with the interop upgrade) a Bridgehub, AssetRouter, NativeTokenVault and Nullifier deployed on every L2, and +they serve the same feature as their L1 counterparts. Namely: + +- The Bridgehub is used to start the transaction. +- The AssetRouter and NativeTokenVault are the bridge contract that handle the tokens. +- The Nullifier is used to prevent reexecution of xL2 txs. + +### Interop process + +![Interop](./img/hyperbridging.png) + +The interop process has 7 main steps, each with its substeps: + +1. Starting the transaction on the sending chain + + - The user/calls calls the Bridgehub contract. If they want to use a bridge they call + `requestL2TransactionTwoBridges`, if they want to make a direct call they call `requestL2TransactionDirect` + function. + - The Bridgehub collects the base token fees necessary for the interop tx to be processed on the destination chain, + and if using the TwoBridges method the calldata and the destination contract ( for more data see Shared bridge + doc). + - The Bridgehub emits a `NewPriorityRequest` event, this is the same as the one in our Mailbox contract. This event + specifies the xL2 txs, which uses the same format as L1->L2 txs. This event can be picked up and used to receive + the txs. + - This new priority request is sent as an L2->L1 message, it is included in the chains merkle tree of emitted txs. + +2. The chain settles its proof on L1 or the Gateway, whichever is used as the settlement layer for the chain. +3. On the Settlement Layer (SL), the MessageRoot is updated in the MessageRoot contract. The new data includes all the + L2->L1 messages that are emitted from the settling chain. +4. The receiving chain picks up the updated MessgeRoot from the Settlement Layer. +5. Now the xL2 txs can be imported on the destination chain. Along with the txs, a merkle proof needs to be sent to link + it to the MessageRoot. +6. Receiving the tx on the destination chain + + - On the destination chain the xL2 txs is verified. This means the merkle proof is checked agains the MessageRoot. + This shows the the xL2 txs was indeed sent. + - After this the txs can be executed. The tx hash is stored in the L2Nullifier contract, so that the txs cannot be + replayed. + - The specified contract is called, with the calldata, and the message sender = + `keccak256(originalMessageSender, originChainId) >> 160`. This is to prevent the collision of the msg.sender + addresses. + +7. The destination chain settles on the SL and the MessageRoot that it imported is checked. diff --git a/docs/specs/zk_chains/shared_bridge.md b/docs/specs/zk_chains/shared_bridge.md index c464a7a154bf..b43d3082b621 100644 --- a/docs/specs/zk_chains/shared_bridge.md +++ b/docs/specs/zk_chains/shared_bridge.md @@ -17,7 +17,7 @@ If you want to know more about ZK Chains, check this We want to create a system where: - ZK Chains should be launched permissionlessly within the ecosystem. -- Hyperbridges should enable unified liquidity for assets across the ecosystem. +- Interop should enable unified liquidity for assets across the ecosystem. - Multi-chain smart contracts need to be easy to develop, which means easy access to traditional bridges, and other supporting architecture. @@ -58,20 +58,19 @@ be able to leverage them when available). #### Bridgehub - Acts as a hub for bridges, so that they have a single point of communication with all ZK Chain contracts. This allows - L1 assets to be locked in the same contract for all ZK Chains, including L3s and validiums. The `Bridgehub` also - implements the following: + L1 assets to be locked in the same contract for all ZK Chains. The `Bridgehub` also implements the following features: - `Registry` This is where ZK Chains can register, starting in a permissioned manner, but with the goal to be - permissionless in the future. This is where their `chainID` is determined. L3s will also register here. This - `Registry` is also where State Transition contracts should register. Each chain has to specify its desired ST when - registering (Initially, only one will be available). + permissionless in the future. This is where their `chainID` is determined. Chains on Gateway will also register here. + This `Registry` is also where Chain Type Manager contracts should register. Each chain has to specify its desired CTM + when registering (Initially, only one will be available). ``` function newChain( uint256 _chainId, - address _stateTransition + address _chainTypeManager ) external returns (uint256 chainId); - function newStateTransition(address _stateTransition) external; + function newChainTypeManager(address _chainTypeManager) external; ``` - `BridgehubMailbox` routes messages to the Diamond proxy’s Mailbox facet based on chainID @@ -79,43 +78,73 @@ be able to leverage them when available). - Same as the current zkEVM [Mailbox](https://github.com/matter-labs/era-contracts/blob/main/l1-contracts/contracts/zksync/facets/Mailbox.sol), just with chainId, - - Ether needs to be deposited and withdrawn from here. - This is where L2 transactions can be requested. ``` - function requestL2Transaction( - uint256 _chainId, - address _contractL2, - uint256 _l2Value, - bytes calldata _calldata, - uint256 _l2GasLimit, - uint256 _l2GasPerPubdataByteLimit, - bytes[] calldata _factoryDeps, - address _refundRecipient - ) public payable override returns (bytes32 canonicalTxHash) { - address proofChain = bridgeheadStorage.proofChain[_chainId]; - canonicalTxHash = IProofChain(proofChain).requestL2TransactionBridgehead( - _chainId, - msg.value, - msg.sender, - _contractL2, - _l2Value, - _calldata, - _l2GasLimit, - _l2GasPerPubdataByteLimit, - _factoryDeps, - _refundRecipient - ); - } + function requestL2TransactionTwoBridges( + L2TransactionRequestTwoBridgesOuter calldata _request + ) ``` -- `Hypermailbox` - - This will allow general message passing (L2<>L2, L2<>L3, etc). This is where the `Mailbox` sends the `Hyperlogs`. - `Hyperlogs` are commitments to these messages sent from a single ZK Chain. `Hyperlogs` are aggregated into a - `HyperRoot` in the `HyperMailbox`. - - This component has not been implemented yet + ``` + struct L2TransactionRequestTwoBridgesOuter { + uint256 chainId; + uint256 mintValue; + uint256 l2Value; + uint256 l2GasLimit; + uint256 l2GasPerPubdataByteLimit; + address refundRecipient; + address secondBridgeAddress; + uint256 secondBridgeValue; + bytes secondBridgeCalldata; + } + ``` -#### Main asset shared bridges +``` + struct L2TransactionRequestTwoBridgesInner { + bytes32 magicValue; + address l2Contract; + bytes l2Calldata; + bytes[] factoryDeps; + bytes32 txDataHash; +} +``` + +- The `requestL2TransactionTwoBridges` function should be used most of the time when bridging to a chain ( the exeption + is when the user bridges directly to a contract on the L2, without using a bridge contract on L1). The logic of it is + the following: + + - The user wants to bridge to chain with the provided `L2TransactionRequestTwoBridgesOuter.chainId`. + - Two bridges are called, the baseTokenBridge (i.e. the L1SharedBridge or L1AssetRouter after the Gateway upgrade) and + an arbitrary second bridge. The Bridgehub will provide the original caller address to both bridges, which can + request that the appropriate amount of tokens are transferred from the caller to the bridge. The caller has to set + the appropriate allowance for both bridges. (Often the bridges coincide, but they don't have to). + - The `L2TransactionRequestTwoBridgesOuter.mintValue` is the amount of baseTokens that will be minted on L2. This is + the amount of tokens that the baseTokenBridge will request from the user. If the baseToken is Eth, it will be + forwarded to the baseTokenBridge. + - The `L2TransactionRequestTwoBridgesOuter.l2Value` is the amount of tokens that will be deposited on L2. The second + bridge and the Mailbox receives this as an input (although our second bridge does not use the value). + - The `L2TransactionRequestTwoBridgesOuter.l2GasLimit` is the maximum amount of gas that will be spent on L2 to + complete the transaction. The Mailbox receives this as an input. + - The `L2TransactionRequestTwoBridgesOuter.l2GasPerPubdataByteLimit` is the maximum amount of gas per pubdata byte + that will be spent on L2 to complete the transaction. The Mailbox receives this as an input. + - The `L2TransactionRequestTwoBridgesOuter.refundRecipient` is the address that will be refunded for the gas spent on + L2. The Mailbox receives this as an input. + - The `L2TransactionRequestTwoBridgesOuter.secondBridgeAddress` is the address of the second bridge that will be + called. This is the arbitrary address that is called from the Bridgehub. + - The `L2TransactionRequestTwoBridgesOuter.secondBridgeValue` is the amount of tokens that will be deposited on L2. + The second bridge receives this value as the baseToken (i.e. Eth on L1). + - The `L2TransactionRequestTwoBridgesOuter.secondBridgeCalldata` is the calldata that will be passed to the second + bridge. This is the arbitrary calldata that is passed from the Bridgehub to the second bridge. + - The secondBridge returns the `L2TransactionRequestTwoBridgesInner` struct to the Bridgehub. This is also passed to + the Mailbox as input. This is where the destination contract, calldata, factoryDeps are determined on the L2. + + This setup allows the user to bridge the baseToken of the origin chain A to a chain B with some other baseToken, by + specifying the A's token in the secondBridgeValue, which will be minted on the destination chain as an ERC20 token, + and specifying the amount of B's token in the mintValue, which will be minted as the baseToken and used to cover the + gas costs. + +#### Main asset shared bridges L2TransactionRequestTwoBridgesInner - Some assets have to be natively supported (ETH, WETH) and it also makes sense to support some generally accepted token standards (ERC20 tokens), as this makes it easy to bridge those tokens (and ensures a single version of them exists on @@ -147,25 +176,18 @@ be able to leverage them when available). ); ``` -This topic is now covered more thoroughly by the Custom native token discussion. - -[Custom native token compatible with Hyperbridging](https://www.notion.so/Custom-native-token-compatible-with-Hyperbridging-54e190a1a76f44248cf84a38304a0641?pvs=21) +#### Chain Type Manager -#### State Transition - -- `StateTransition` A state transition manages proof verification and DA for multiple chains. It also implements the +- `ChainTypeManager` A chain type manager manages proof verification and DA for multiple chains. It also implements the following functionalities: - - `StateTransitionRegistry` The ST is shared for multiple chains, so initialization and upgrades have to be the same - for all chains. Registration is not permissionless but happens based on the registrations in the bridgehub’s - `Registry`. At registration a `DiamondProxy` is deployed and initialized with the appropriate `Facets` for each ZK - Chain. + - `ChainTypeRegistry` The ST is shared for multiple chains, so initialization and upgrades have to be the same for all + chains. Registration is not permissionless but happens based on the registrations in the bridgehub’s `Registry`. At + registration a `DiamondProxy` is deployed and initialized with the appropriate `Facets` for each ZK Chain. - `Facets` and `Verifier` are shared across chains that relies on the same ST: `Base`, `Executor` , `Getters`, `Admin` , `Mailbox.`The `Verifier` is the contract that actually verifies the proof, and is called by the `Executor`. - Upgrade Mechanism The system requires all chains to be up-to-date with the latest implementation, so whenever an update is needed, we have to “force” each chain to update, but due to decentralization, we have to give each chain a - time frame (more information in the - [Upgrade Mechanism](https://www.notion.so/ZK-Stack-shared-bridge-alpha-version-a37c4746f8b54fb899d67e474bfac3bb?pvs=21) - section). This is done in the update mechanism contract, this is where the bootloader and system contracts are + time frame. This is done in the update mechanism contract, this is where the bootloader and system contracts are published, and the `ProposedUpgrade` is stored. Then each chain can call this upgrade for themselves as needed. After the deadline is over, the not-updated chains are frozen, that is, cannot post new proofs. Frozen chains can unfreeze by updating their proof system. @@ -180,6 +202,7 @@ This topic is now covered more thoroughly by the Custom native token discussion. - A chain might implement its own specific consensus mechanism. This needs its own contracts. Only this contract will be able to submit proofs to the State Transition contract. +- DA contracts. - Currently, the `ValidatorTimelock` is an example of such a contract. ### Components interactions @@ -199,22 +222,6 @@ features required to process proofs. The chain ID is set in the VM in a special -#### WETH Contract - -Ether, the native gas token is part of the core system contracts, so deploying it is not necessary. But WETH is just a -smart contract, it needs to be deployed and initialised. This happens from the L1 WETH bridge. This deploys on L2 the -corresponding bridge and ERC20 contract. This is deployed from L1, but the L2 address is known at deployment time. - -![deployWeth.png](./img/deployWeth.png) - -#### Deposit WETH - -The user can deposit WETH into the ecosystem using the WETH bridge on L1. The destination chain ID has to be specified. -The Bridgehub unwraps the WETH, and keeps the ETH, and send a message to the destination L2 to mint WETH to the -specified address. - -![depositWeth.png](./img/depositWeth.png) - --- ### Common Standards and Upgrades diff --git a/etc/contracts-test-data/contracts/mock-evm/mock-evm.sol b/etc/contracts-test-data/contracts/mock-evm/mock-evm.sol index 5f4de59681fd..baa0d37b7530 100644 --- a/etc/contracts-test-data/contracts/mock-evm/mock-evm.sol +++ b/etc/contracts-test-data/contracts/mock-evm/mock-evm.sol @@ -68,7 +68,7 @@ contract MockContractDeployer { Version1 } - address constant CODE_ORACLE_ADDR = address(0x8012); + IAccountCodeStorage constant ACCOUNT_CODE_STORAGE_CONTRACT = IAccountCodeStorage(address(0x8002)); MockKnownCodeStorage constant KNOWN_CODE_STORAGE_CONTRACT = MockKnownCodeStorage(address(0x8004)); /// The returned value is obviously incorrect in the general case, but works well enough when called by the bootloader. @@ -78,15 +78,166 @@ contract MockContractDeployer { /// Replaces real deployment with publishing a surrogate EVM "bytecode". /// @param _salt bytecode hash - /// @param _bytecodeHash ignored, since it's not possible to set arbitrarily /// @param _input bytecode to publish function create( bytes32 _salt, - bytes32 _bytecodeHash, + bytes32, // ignored, since it's not possible to set arbitrarily bytes calldata _input ) external payable returns (address) { KNOWN_CODE_STORAGE_CONTRACT.setEVMBytecodeHash(_salt); KNOWN_CODE_STORAGE_CONTRACT.publishEVMBytecode(_input); - return address(0); + address newAddress = address(uint160(msg.sender) + 1); + ACCOUNT_CODE_STORAGE_CONTRACT.storeAccountConstructedCodeHash(newAddress, _salt); + return newAddress; + } +} + +interface IAccountCodeStorage { + function getRawCodeHash(address _address) external view returns (bytes32); + function storeAccountConstructedCodeHash(address _address, bytes32 _hash) external; +} + +interface IRecursiveContract { + function recurse(uint _depth) external returns (uint); +} + +/// Native incrementing library. Not actually a library to simplify deployment. +contract IncrementingContract { + // Should not collide with other storage slots + uint constant INCREMENTED_SLOT = 0x123; + + function getIncrementedValue() public view returns (uint _value) { + assembly { + _value := sload(INCREMENTED_SLOT) + } + } + + function increment(address _thisAddress, uint _thisBalance) external { + require(msg.sender == tx.origin, "msg.sender not retained"); + require(address(this) == _thisAddress, "this address"); + require(address(this).balance == _thisBalance, "this balance"); + assembly { + sstore(INCREMENTED_SLOT, add(sload(INCREMENTED_SLOT), 1)) + } + } + + /// Tests delegation to a native or EVM contract at the specified target. + function testDelegateCall(address _target) external { + uint valueSnapshot = getIncrementedValue(); + (bool success, ) = _target.delegatecall(abi.encodeCall( + IncrementingContract.increment, + (address(this), address(this).balance) + )); + require(success, "delegatecall reverted"); + require(getIncrementedValue() == valueSnapshot + 1, "invalid value"); + } + + function testStaticCall(address _target, uint _expectedValue) external { + (bool success, bytes memory rawValue) = _target.staticcall(abi.encodeCall( + this.getIncrementedValue, + () + )); + require(success, "static call reverted"); + (uint value) = abi.decode(rawValue, (uint)); + require(value == _expectedValue, "value mismatch"); + + (success, ) = _target.staticcall(abi.encodeCall( + IncrementingContract.increment, + (address(this), address(this).balance) + )); + require(!success, "staticcall should've reverted"); + } +} + +uint constant EVM_EMULATOR_STIPEND = 1 << 30; + +/** + * Mock EVM emulator used in low-level tests. + */ +contract MockEvmEmulator is IRecursiveContract, IncrementingContract { + IAccountCodeStorage constant ACCOUNT_CODE_STORAGE_CONTRACT = IAccountCodeStorage(address(0x8002)); + + /// Set to `true` for testing logic sanity. + bool isUserSpace; + + modifier validEvmEntry() { + if (!isUserSpace) { + require(gasleft() >= EVM_EMULATOR_STIPEND, "no stipend"); + // Fetch bytecode for the executed contract. + bytes32 bytecodeHash = ACCOUNT_CODE_STORAGE_CONTRACT.getRawCodeHash(address(this)); + require(bytecodeHash != bytes32(0), "called contract not deployed"); + uint bytecodeVersion = uint(bytecodeHash) >> 248; + require(bytecodeVersion == 2, "non-EVM bytecode"); + + // Check that members of the current address are well-defined. + require(address(this).code.length != 0, "invalid code"); + require(address(this).codehash == bytecodeHash, "bytecode hash mismatch"); + } + _; + } + + function testPayment(uint _expectedValue, uint _expectedBalance) public payable validEvmEntry { + require(msg.value == _expectedValue, "unexpected msg.value"); + require(address(this).balance == _expectedBalance, "unexpected balance"); + } + + IRecursiveContract recursionTarget; + + function recurse(uint _depth) public validEvmEntry returns (uint) { + require(gasleft() < 2 * EVM_EMULATOR_STIPEND, "stipend provided multiple times"); + + if (_depth <= 1) { + return 1; + } else { + IRecursiveContract target = (address(recursionTarget) == address(0)) ? this : recursionTarget; + // The real emulator limits amount of gas when performing far calls by EVM gas, so we emulate this behavior as well. + uint gasToSend = isUserSpace ? gasleft() : (gasleft() - EVM_EMULATOR_STIPEND); + return target.recurse{gas: gasToSend}(_depth - 1) * _depth; + } + } + + function testRecursion(uint _depth, uint _expectedValue) external validEvmEntry returns (uint) { + require(recurse(_depth) == _expectedValue, "incorrect recursion"); + } + + function testExternalRecursion(uint _depth, uint _expectedValue) external validEvmEntry returns (uint) { + recursionTarget = new NativeRecursiveContract(IRecursiveContract(this)); + uint returnedValue = recurse(_depth); + recursionTarget = this; // This won't work on revert, but for tests, it's good enough + require(returnedValue == _expectedValue, "incorrect recursion"); + } + + MockContractDeployer constant CONTRACT_DEPLOYER_CONTRACT = MockContractDeployer(address(0x8006)); + + /// Emulates EVM contract deployment and a subsequent call to it in a single transaction. + function testDeploymentAndCall(bytes32 _evmBytecodeHash, bytes calldata _evmBytecode) external validEvmEntry { + IRecursiveContract newContract = IRecursiveContract(CONTRACT_DEPLOYER_CONTRACT.create( + _evmBytecodeHash, + _evmBytecodeHash, + _evmBytecode + )); + require(uint160(address(newContract)) == uint160(address(this)) + 1, "unexpected address"); + require(address(newContract).code.length > 0, "contract code length"); + require(address(newContract).codehash != bytes32(0), "contract code hash"); + + uint gasToSend = gasleft() - EVM_EMULATOR_STIPEND; + require(newContract.recurse{gas: gasToSend}(5) == 120, "unexpected recursive result"); + } + + fallback() external validEvmEntry { + require(msg.data.length == 0, "unsupported call"); + } +} + +contract NativeRecursiveContract is IRecursiveContract { + IRecursiveContract target; + + constructor(IRecursiveContract _target) { + target = _target; + } + + function recurse(uint _depth) external returns (uint) { + require(gasleft() < EVM_EMULATOR_STIPEND, "stipend spilled to native contract"); + return (_depth <= 1) ? 1 : target.recurse(_depth - 1) * _depth; } } diff --git a/etc/env/consensus_config.yaml b/etc/env/consensus_config.yaml index 304ea31fac9c..2564865eeb31 100644 --- a/etc/env/consensus_config.yaml +++ b/etc/env/consensus_config.yaml @@ -1,3 +1,4 @@ +port: 3054 server_addr: "127.0.0.1:3054" public_addr: "127.0.0.1:3054" max_payload_size: 2500000 diff --git a/etc/env/en_consensus_config.yaml b/etc/env/en_consensus_config.yaml index f759e72e891c..5c428866cb6c 100644 --- a/etc/env/en_consensus_config.yaml +++ b/etc/env/en_consensus_config.yaml @@ -1,3 +1,4 @@ +port: 3055 server_addr: '127.0.0.1:3055' public_addr: '127.0.0.1:3055' max_payload_size: 2500000 diff --git a/etc/env/file_based/general.yaml b/etc/env/file_based/general.yaml index a4ba8c0201a6..017d79dbe736 100644 --- a/etc/env/file_based/general.yaml +++ b/etc/env/file_based/general.yaml @@ -375,3 +375,10 @@ da_dispatcher: external_proof_integration_api: http_port: 3073 + +consensus: + port: 3054 + server_addr: "127.0.0.1:3054" + public_addr: "127.0.0.1:3054" + max_payload_size: 2500000 + gossip_dynamic_inbound_limit: 100 diff --git a/etc/nix/tee_prover.nix b/etc/nix/tee_prover.nix index 0b424522dffb..55545d1bb8e4 100644 --- a/etc/nix/tee_prover.nix +++ b/etc/nix/tee_prover.nix @@ -1,12 +1,19 @@ -{ cargoArtifacts -, craneLib +{ craneLib , commonArgs }: -craneLib.buildPackage (commonArgs // { +let pname = "zksync_tee_prover"; + cargoExtraArgs = "--locked -p zksync_tee_prover"; +in +craneLib.buildPackage (commonArgs // { + inherit pname; version = (builtins.fromTOML (builtins.readFile ../../core/bin/zksync_tee_prover/Cargo.toml)).package.version; - cargoExtraArgs = "-p zksync_tee_prover --bin zksync_tee_prover"; - inherit cargoArtifacts; + inherit cargoExtraArgs; + + cargoArtifacts = craneLib.buildDepsOnly (commonArgs // { + inherit pname; + inherit cargoExtraArgs; + }); postInstall = '' strip $out/bin/zksync_tee_prover diff --git a/etc/nix/zksync.nix b/etc/nix/zksync.nix index c5fffc48b09d..1ecac58b5d91 100644 --- a/etc/nix/zksync.nix +++ b/etc/nix/zksync.nix @@ -1,12 +1,14 @@ -{ cargoArtifacts -, craneLib +{ craneLib , commonArgs }: craneLib.buildPackage (commonArgs // { pname = "zksync"; version = (builtins.fromTOML (builtins.readFile ../../core/bin/zksync_tee_prover/Cargo.toml)).package.version; cargoExtraArgs = "--all"; - inherit cargoArtifacts; + + cargoArtifacts = craneLib.buildDepsOnly (commonArgs // { + pname = "zksync-era-workspace"; + }); outputs = [ "out" diff --git a/flake.nix b/flake.nix index ef618816f9c9..8c08e880910d 100644 --- a/flake.nix +++ b/flake.nix @@ -47,7 +47,7 @@ packages = { # to ease potential cross-compilation, the overlay is used inherit (appliedOverlay.zksync-era) zksync tee_prover container-tee-prover-azure container-tee-prover-dcap; - default = appliedOverlay.zksync-era.zksync; + default = appliedOverlay.zksync-era.tee_prover; }; devShells.default = appliedOverlay.zksync-era.devShell; @@ -91,7 +91,7 @@ ./Cargo.toml ./core ./prover - ./zk_toolbox + ./zkstack_cli ./.github/release-please/manifest.json ]; }; @@ -107,10 +107,6 @@ strictDeps = true; inherit hardeningEnable; }; - - cargoArtifacts = craneLib.buildDepsOnly (commonArgs // { - pname = "zksync-era-workspace"; - }); in { zksync-era = rec { @@ -120,12 +116,11 @@ }; zksync = pkgs.callPackage ./etc/nix/zksync.nix { - inherit cargoArtifacts; inherit craneLib; inherit commonArgs; }; + tee_prover = pkgs.callPackage ./etc/nix/tee_prover.nix { - inherit cargoArtifacts; inherit craneLib; inherit commonArgs; }; diff --git a/infrastructure/zk/src/fmt.ts b/infrastructure/zk/src/fmt.ts index e58cdbc8e547..b9f7f1b9d60b 100644 --- a/infrastructure/zk/src/fmt.ts +++ b/infrastructure/zk/src/fmt.ts @@ -48,7 +48,7 @@ export async function rustfmt(check: boolean = false) { const dirs = [ process.env.ZKSYNC_HOME as string, `${process.env.ZKSYNC_HOME}/prover`, - `${process.env.ZKSYNC_HOME}/zk_toolbox` + `${process.env.ZKSYNC_HOME}/zkstack_cli` ]; for (const dir of dirs) { diff --git a/infrastructure/zk/src/lint.ts b/infrastructure/zk/src/lint.ts index 7a24881c0f96..49ae4d0753ec 100644 --- a/infrastructure/zk/src/lint.ts +++ b/infrastructure/zk/src/lint.ts @@ -38,12 +38,12 @@ async function proverClippy() { await utils.spawn('cargo clippy --tests --locked -- -D warnings'); } -async function toolboxClippy() { - process.chdir(`${process.env.ZKSYNC_HOME}/zk_toolbox`); +async function zkstackClippy() { + process.chdir(`${process.env.ZKSYNC_HOME}/zkstack_cli`); await utils.spawn('cargo clippy --tests --locked -- -D warnings'); } -const ARGS = [...EXTENSIONS, 'rust', 'prover', 'contracts', 'toolbox'] as const; +const ARGS = [...EXTENSIONS, 'rust', 'prover', 'contracts', 'zkstack_cli'] as const; export const command = new Command('lint') .description('lint code') @@ -61,8 +61,8 @@ export const command = new Command('lint') case 'contracts': await lintContracts(cmd.check); break; - case 'toolbox': - await toolboxClippy(); + case 'zkstack_cli': + await zkstackClippy(); break; default: await lint(extension, cmd.check); @@ -72,7 +72,7 @@ export const command = new Command('lint') promises.push(lintContracts(cmd.check)); promises.push(clippy()); promises.push(proverClippy()); - promises.push(toolboxClippy()); + promises.push(zkstackClippy()); await Promise.all(promises); } }); diff --git a/prover/docs/05_proving_batch.md b/prover/docs/05_proving_batch.md index e09a44cb0ff7..c35de975bf71 100644 --- a/prover/docs/05_proving_batch.md +++ b/prover/docs/05_proving_batch.md @@ -14,17 +14,25 @@ GPU, which requires an NVIDIA A100 80GB GPU. ### Prerequisites -First of all, you need to install CUDA drivers, all other things will be dealt with by `zk_inception` and `prover_cli` -tools. For that, check the following [guide](./02_setup.md)(you can skip bellman-cuda step). +First of all, you need to install CUDA drivers, all other things will be dealt with by `zkstack` and `prover_cli` tools. +For that, check the following [guide](./02_setup.md)(you can skip bellman-cuda step). Install the prerequisites, which you can find [here](https://github.com/matter-labs/zksync-era/blob/main/docs/guides/setup-dev.md). Note, that if you are not using Google VM instance, you also need to install [gcloud](https://cloud.google.com/sdk/docs/install#deb). -Now, you can use `zk_inception` and `prover_cli` tools for setting up the env and running prover subsystem. +Now, you can use `zkstack` and `prover_cli` tools for setting up the env and running prover subsystem. -```shell -cargo +nightly-2024-08-01 install --git https://github.com/matter-labs/zksync-era/ --locked zk_inception zk_supervisor prover_cli --force +First, install `zkstackup` with: + +```bash +curl -L https://raw.githubusercontent.com/matter-labs/zksync-era/main/zkstack_cli/zkstackup/install | bash +``` + +Then install the most recent version of `zkstack` with: + +```bash +zkstackup ``` ## Initializing system @@ -33,14 +41,14 @@ After you have installed the tool, you can create ecosystem(you need to run only running: ```shell -zk_inception ecosystem create --l1-network=localhost --prover-mode=gpu --wallet-creation=localhost --l1-batch-commit-data-generator-mode=rollup --start-containers=true +zkstack ecosystem create --l1-network=localhost --prover-mode=gpu --wallet-creation=localhost --l1-batch-commit-data-generator-mode=rollup --start-containers=true ``` The command will create the ecosystem and all the necessary components for the prover subsystem. You can leave default values for all the prompts you will see Now, you need to initialize the prover subsystem by running: ```shell -zk_inception prover init --shall-save-to-public-bucket=false --setup-database=true --use-default=true --dont-drop=false +zkstack prover init --shall-save-to-public-bucket=false --setup-database=true --use-default=true --dont-drop=false ``` For prompts you can leave default values as well. @@ -87,13 +95,23 @@ After you have the data, you need to prepare the system to run the batch. So, da the protocol version it should use. You can do that with running ```shell -zk_supervisor prover-version +zkstack dev prover info ``` Example output: ```shell -Current protocol version found in zksync-era: 0.24.2, snark_wrapper: "0x14f97b81e54b35fe673d8708cc1a19e1ea5b5e348e12d31e39824ed4f42bbca2" +=============================== + +Current prover setup information: + +Protocol version: 0.24.2 + +Snark wrapper: 0x14f97b81e54b35fe673d8708cc1a19e1ea5b5e348e12d31e39824ed4f42bbca2 + +Database URL: postgres://postgres:notsecurepassword@localhost:5432/zksync_prover_localhost_era + +=============================== ``` This command will provide you with the information about the semantic protocol version(you need to know only minor and @@ -118,7 +136,7 @@ prover_cli insert-batch --number= --version=` - -###### **Subcommands:** - -- `database` — Database related commands -- `test` — Run tests -- `clean` — Clean artifacts -- `snapshot` — Snapshots creator -- `lint` — Lint code -- `fmt` — Format code -- `prover-version` — Protocol version used by provers - -###### **Options:** - -- `-v`, `--verbose` — Verbose mode -- `--chain ` — Chain to use -- `--ignore-prerequisites` — Ignores prerequisites checks - -## `zk_supervisor database` - -Database related commands - -**Usage:** `zk_supervisor database ` - -###### **Subcommands:** - -- `check-sqlx-data` — Check sqlx-data.json is up to date. If no databases are selected, all databases will be checked. -- `drop` — Drop databases. If no databases are selected, all databases will be dropped. -- `migrate` — Migrate databases. If no databases are selected, all databases will be migrated. -- `new-migration` — Create new migration -- `prepare` — Prepare sqlx-data.json. If no databases are selected, all databases will be prepared. -- `reset` — Reset databases. If no databases are selected, all databases will be reset. -- `setup` — Setup databases. If no databases are selected, all databases will be setup. - -## `zk_supervisor database check-sqlx-data` - -Check sqlx-data.json is up to date. If no databases are selected, all databases will be checked. - -**Usage:** `zk_supervisor database check-sqlx-data [OPTIONS]` - -###### **Options:** - -- `-p`, `--prover ` — Prover database - - Possible values: `true`, `false` - -- `-c`, `--core ` — Core database - - Possible values: `true`, `false` - -## `zk_supervisor database drop` - -Drop databases. If no databases are selected, all databases will be dropped. - -**Usage:** `zk_supervisor database drop [OPTIONS]` - -###### **Options:** - -- `-p`, `--prover ` — Prover database - - Possible values: `true`, `false` - -- `-c`, `--core ` — Core database - - Possible values: `true`, `false` - -## `zk_supervisor database migrate` - -Migrate databases. If no databases are selected, all databases will be migrated. - -**Usage:** `zk_supervisor database migrate [OPTIONS]` - -###### **Options:** - -- `-p`, `--prover ` — Prover database - - Possible values: `true`, `false` - -- `-c`, `--core ` — Core database - - Possible values: `true`, `false` - -## `zk_supervisor database new-migration` - -Create new migration - -**Usage:** `zk_supervisor database new-migration [OPTIONS]` - -###### **Options:** - -- `--database ` — Database to create new migration for - - Possible values: `prover`, `core` - -- `--name ` — Migration name - -## `zk_supervisor database prepare` - -Prepare sqlx-data.json. If no databases are selected, all databases will be prepared. - -**Usage:** `zk_supervisor database prepare [OPTIONS]` - -###### **Options:** - -- `-p`, `--prover ` — Prover database - - Possible values: `true`, `false` - -- `-c`, `--core ` — Core database - - Possible values: `true`, `false` - -## `zk_supervisor database reset` - -Reset databases. If no databases are selected, all databases will be reset. - -**Usage:** `zk_supervisor database reset [OPTIONS]` - -###### **Options:** - -- `-p`, `--prover ` — Prover database - - Possible values: `true`, `false` - -- `-c`, `--core ` — Core database - - Possible values: `true`, `false` - -## `zk_supervisor database setup` - -Setup databases. If no databases are selected, all databases will be setup. - -**Usage:** `zk_supervisor database setup [OPTIONS]` - -###### **Options:** - -- `-p`, `--prover ` — Prover database - - Possible values: `true`, `false` - -- `-c`, `--core ` — Core database - - Possible values: `true`, `false` - -## `zk_supervisor test` - -Run tests - -**Usage:** `zk_supervisor test ` - -###### **Subcommands:** - -- `integration` — Run integration tests -- `revert` — Run revert tests -- `recovery` — Run recovery tests -- `upgrade` — Run upgrade tests -- `rust` — Run unit-tests, accepts optional cargo test flags -- `l1-contracts` — Run L1 contracts tests -- `prover` — Run prover tests - -## `zk_supervisor test integration` - -Run integration tests - -**Usage:** `zk_supervisor test integration [OPTIONS]` - -###### **Options:** - -- `-e`, `--external-node` — Run tests for external node - -## `zk_supervisor test revert` - -Run revert tests - -**Usage:** `zk_supervisor test revert [OPTIONS]` - -###### **Options:** - -- `--enable-consensus` — Enable consensus -- `-e`, `--external-node` — Run tests for external node - -## `zk_supervisor test recovery` - -Run recovery tests - -**Usage:** `zk_supervisor test recovery [OPTIONS]` - -###### **Options:** - -- `-s`, `--snapshot` — Run recovery from a snapshot instead of genesis - -## `zk_supervisor test upgrade` - -Run upgrade tests - -**Usage:** `zk_supervisor test upgrade` - -## `zk_supervisor test rust` - -Run unit-tests, accepts optional cargo test flags - -**Usage:** `zk_supervisor test rust [OPTIONS]` - -###### **Options:** - -- `--options ` — Cargo test flags - -## `zk_supervisor test l1-contracts` - -Run L1 contracts tests - -**Usage:** `zk_supervisor test l1-contracts` - -## `zk_supervisor test prover` - -Run prover tests - -**Usage:** `zk_supervisor test prover` - -## `zk_supervisor clean` - -Clean artifacts - -**Usage:** `zk_supervisor clean ` - -###### **Subcommands:** - -- `all` — Remove containers and contracts cache -- `containers` — Remove containers and docker volumes -- `contracts-cache` — Remove contracts caches - -## `zk_supervisor clean all` - -Remove containers and contracts cache - -**Usage:** `zk_supervisor clean all` - -## `zk_supervisor clean containers` - -Remove containers and docker volumes - -**Usage:** `zk_supervisor clean containers` - -## `zk_supervisor clean contracts-cache` - -Remove contracts caches - -**Usage:** `zk_supervisor clean contracts-cache` - -## `zk_supervisor snapshot` - -Snapshots creator - -**Usage:** `zk_supervisor snapshot ` - -###### **Subcommands:** - -- `create` — - -## `zk_supervisor snapshot create` - -**Usage:** `zk_supervisor snapshot create` - -## `zk_supervisor lint` - -Lint code - -**Usage:** `zk_supervisor lint [OPTIONS]` - -###### **Options:** - -- `-c`, `--check` -- `-e`, `--extensions ` - - Possible values: `md`, `sol`, `js`, `ts`, `rs` - -## `zk_supervisor fmt` - -Format code - -**Usage:** `zk_supervisor fmt [OPTIONS] [COMMAND]` - -###### **Subcommands:** - -- `rustfmt` — -- `contract` — -- `prettier` — - -###### **Options:** - -- `-c`, `--check` - -## `zk_supervisor fmt rustfmt` - -**Usage:** `zk_supervisor fmt rustfmt` - -## `zk_supervisor fmt contract` - -**Usage:** `zk_supervisor fmt contract` - -## `zk_supervisor fmt prettier` - -**Usage:** `zk_supervisor fmt prettier [OPTIONS]` - -###### **Options:** - -- `-e`, `--extensions ` - - Possible values: `md`, `sol`, `js`, `ts`, `rs` - -## `zk_supervisor prover info` - -Prints prover protocol version, snark wrapper and prover database URL - -**Usage:** `zk_supervisor prover info` - -## `zk_supervisor prover insert-version` - -Inserts protocol version into prover database. - -**Usage:** `zk_supervisor prover insert-version [OPTIONS]` - -###### **Options:** - -- `--version ` — Protocol version in semantic format(`x.y.z`). Major version should be 0. -- `--snark-wrapper ` — Snark wrapper hash. -- `--default` - use default values for protocol version and snark wrapper hash (the ones found in zksync-era). - -## `zk_supervisor prover insert-batch` - -Inserts batch into prover database. - -**Usage:** `zk_supervisor prover insert-batch` - -###### **Options:** - -- `--number ` — Number of the batch to insert. -- `--version ` — Protocol version in semantic format(`x.y.z`). Major version should be 0. -- `--default` - use default value for protocol version (the one found in zksync-era). - -


- - This document was generated automatically by -clap-markdown. diff --git a/zk_toolbox/crates/zk_supervisor/src/main.rs b/zk_toolbox/crates/zk_supervisor/src/main.rs deleted file mode 100644 index f99970489bcd..000000000000 --- a/zk_toolbox/crates/zk_supervisor/src/main.rs +++ /dev/null @@ -1,154 +0,0 @@ -use clap::{Parser, Subcommand}; -use commands::{ - config_writer::ConfigWriterArgs, contracts::ContractsArgs, database::DatabaseCommands, - lint::LintArgs, prover::ProverCommands, send_transactions::args::SendTransactionsArgs, - snapshot::SnapshotCommands, test::TestCommands, -}; -use common::{ - check_general_prerequisites, - config::{global_config, init_global_config, GlobalConfig}, - error::log_error, - init_prompt_theme, logger, - version::version_message, -}; -use config::EcosystemConfig; -use messages::{ - msg_global_chain_does_not_exist, MSG_CONFIG_WRITER_ABOUT, MSG_CONTRACTS_ABOUT, - MSG_GENERATE_GENESIS_ABOUT, MSG_PROVER_VERSION_ABOUT, MSG_SEND_TXNS_ABOUT, - MSG_SUBCOMMAND_CLEAN, MSG_SUBCOMMAND_DATABASE_ABOUT, MSG_SUBCOMMAND_FMT_ABOUT, - MSG_SUBCOMMAND_LINT_ABOUT, MSG_SUBCOMMAND_SNAPSHOTS_CREATOR_ABOUT, MSG_SUBCOMMAND_TESTS_ABOUT, -}; -use xshell::Shell; - -use crate::commands::{clean::CleanCommands, fmt::FmtArgs}; - -mod commands; -mod consts; -mod dals; -mod defaults; -mod messages; - -#[derive(Parser, Debug)] -#[command( - version = version_message(env!("CARGO_PKG_VERSION")), - about -)] -struct Supervisor { - #[command(subcommand)] - command: SupervisorSubcommands, - #[clap(flatten)] - global: SupervisorGlobalArgs, -} - -#[derive(Subcommand, Debug)] -enum SupervisorSubcommands { - #[command(subcommand, about = MSG_SUBCOMMAND_DATABASE_ABOUT, alias = "db")] - Database(DatabaseCommands), - #[command(subcommand, about = MSG_SUBCOMMAND_TESTS_ABOUT, alias = "t")] - Test(TestCommands), - #[command(subcommand, about = MSG_SUBCOMMAND_CLEAN)] - Clean(CleanCommands), - #[command(subcommand, about = MSG_SUBCOMMAND_SNAPSHOTS_CREATOR_ABOUT)] - Snapshot(SnapshotCommands), - #[command(about = MSG_SUBCOMMAND_LINT_ABOUT, alias = "l")] - Lint(LintArgs), - #[command(about = MSG_SUBCOMMAND_FMT_ABOUT)] - Fmt(FmtArgs), - #[command(hide = true)] - Markdown, - #[command(subcommand, about = MSG_PROVER_VERSION_ABOUT)] - Prover(ProverCommands), - #[command(about = MSG_GENERATE_GENESIS_ABOUT, alias = "genesis")] - GenerateGenesis, - #[command(about = MSG_CONTRACTS_ABOUT)] - Contracts(ContractsArgs), - #[command(about = MSG_CONFIG_WRITER_ABOUT, alias = "o")] - ConfigWriter(ConfigWriterArgs), - #[command(about = MSG_SEND_TXNS_ABOUT)] - SendTransactions(SendTransactionsArgs), -} - -#[derive(Parser, Debug)] -#[clap(next_help_heading = "Global options")] -struct SupervisorGlobalArgs { - /// Verbose mode - #[clap(short, long, global = true)] - verbose: bool, - /// Chain to use - #[clap(long, global = true)] - chain: Option, - /// Ignores prerequisites checks - #[clap(long, global = true)] - ignore_prerequisites: bool, -} - -#[tokio::main] -async fn main() -> anyhow::Result<()> { - human_panic::setup_panic!(); - - // We must parse arguments before printing the intro, because some autogenerated - // Clap commands (like `--version` would look odd otherwise). - let args = Supervisor::parse(); - - init_prompt_theme(); - - logger::new_empty_line(); - logger::intro(); - - let shell = Shell::new().unwrap(); - init_global_config_inner(&shell, &args.global)?; - - if !global_config().ignore_prerequisites { - check_general_prerequisites(&shell); - } - - match run_subcommand(args, &shell).await { - Ok(_) => {} - Err(error) => { - log_error(error); - std::process::exit(1); - } - } - - Ok(()) -} - -async fn run_subcommand(args: Supervisor, shell: &Shell) -> anyhow::Result<()> { - match args.command { - SupervisorSubcommands::Database(command) => commands::database::run(shell, command).await?, - SupervisorSubcommands::Test(command) => commands::test::run(shell, command).await?, - SupervisorSubcommands::Clean(command) => commands::clean::run(shell, command)?, - SupervisorSubcommands::Snapshot(command) => commands::snapshot::run(shell, command).await?, - SupervisorSubcommands::Markdown => { - clap_markdown::print_help_markdown::(); - } - SupervisorSubcommands::Lint(args) => commands::lint::run(shell, args)?, - SupervisorSubcommands::Fmt(args) => commands::fmt::run(shell.clone(), args).await?, - SupervisorSubcommands::Prover(command) => commands::prover::run(shell, command).await?, - SupervisorSubcommands::GenerateGenesis => commands::genesis::run(shell).await?, - SupervisorSubcommands::Contracts(args) => commands::contracts::run(shell, args)?, - SupervisorSubcommands::ConfigWriter(args) => commands::config_writer::run(shell, args)?, - SupervisorSubcommands::SendTransactions(args) => { - commands::send_transactions::run(shell, args).await? - } - } - Ok(()) -} - -fn init_global_config_inner(shell: &Shell, args: &SupervisorGlobalArgs) -> anyhow::Result<()> { - if let Some(name) = &args.chain { - if let Ok(config) = EcosystemConfig::from_file(shell) { - let chains = config.list_of_chains(); - if !chains.contains(name) { - anyhow::bail!(msg_global_chain_does_not_exist(name, &chains.join(", "))); - } - } - } - - init_global_config(GlobalConfig { - verbose: args.verbose, - chain_name: args.chain.clone(), - ignore_prerequisites: args.ignore_prerequisites, - }); - Ok(()) -} diff --git a/zk_toolbox/zkup/README.md b/zk_toolbox/zkup/README.md deleted file mode 100644 index d6e3e634688c..000000000000 --- a/zk_toolbox/zkup/README.md +++ /dev/null @@ -1,76 +0,0 @@ -# zkup - zk_toolbox Installer - -`zkup` is a script designed to simplify the installation of -[zk_toolbox](https://github.com/matter-labs/zksync-era/tree/main/zk_toolbox). It allows you to install the tool from a -local directory or directly from a GitHub repository. - -## Getting Started - -To install `zkup`, run the following command: - -```bash -curl -L https://raw.githubusercontent.com/matter-labs/zksync-era/main/zk_toolbox/zkup/install | bash -``` - -After installing `zkup`, you can use it to install `zk_toolbox` with: - -```bash -zkup -``` - -## Usage - -The `zkup` script provides various options for installing `zk_toolbox`: - -### Options - -- `-p, --path ` - Specify a local path to install `zk_toolbox` from. This option is ignored if `--repo` is provided. - -- `-r, --repo ` - GitHub repository to install from (e.g., "matter-labs/zksync-era"). Defaults to "matter-labs/zksync-era". - -- `-b, --branch ` - Git branch to use when installing from a repository. Ignored if `--commit` or `--version` is provided. - -- `-c, --commit ` - Git commit hash to use when installing from a repository. Ignored if `--branch` or `--version` is provided. - -- `-v, --version ` - Git tag to use when installing from a repository. Ignored if `--branch` or `--commit` is provided. - -- `--inception` - Installs `zk_inception` from the repository. By default, `zkup` installs `zk_inception` and `zk_supervisor`. - -- `--supervisor` - Installs `zk_supervisor` from the repository. - -### Local Installation - -If you provide a local path using the `-p` or `--path` option, `zkup` will install `zk_toolbox` from that directory. -Note that repository-specific arguments (`--repo`, `--branch`, `--commit`, `--version`) will be ignored in this case to -preserve git state. - -### Repository Installation - -By default, `zkup` installs `zk_toolbox` from the "matter-labs/zksync-era" GitHub repository. You can specify a -different repository, branch, commit, or version using the respective options. If multiple arguments are provided, -`zkup` will prioritize them as follows: - -- `--version` -- `--commit` -- `--branch` - -### Examples - -**Install from a GitHub repository with a specific version:** - -```bash -zkup --repo matter-labs/zksync-era --version 0.1.1 -``` - -**Install from a local path, only installing `zk_inception`:** - -```bash -zkup --path /path/to/local/zk_toolbox --inception -``` diff --git a/zk_toolbox/zkup/install b/zk_toolbox/zkup/install deleted file mode 100755 index 4e24b03dec46..000000000000 --- a/zk_toolbox/zkup/install +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash -set -eo pipefail - -BASE_DIR=${XDG_CONFIG_HOME:-$HOME} -ZKT_DIR=${ZKT_DIR:-"$BASE_DIR/.zkt"} -ZKT_BIN_DIR="$ZKT_DIR/bin" - -BIN_URL="https://raw.githubusercontent.com/matter-labs/zksync-era/main/zk_toolbox/zkup/zkup" -BIN_PATH="$ZKT_BIN_DIR/zkup" - -mkdir -p "$ZKT_BIN_DIR" -curl -sSfL "$BIN_URL" -o "$BIN_PATH" -chmod +x "$BIN_PATH" - -if [[ ":$PATH:" == *":${ZKT_BIN_DIR}:"* ]]; then - echo "zkup: found ${ZKT_BIN_DIR} in PATH" - exit 0 -fi - -case $SHELL in -*/zsh) - PROFILE="${ZDOTDIR-"$HOME"}/.zshenv" - ;; -*/bash) - PROFILE="$HOME/.bashrc" - ;; -*/fish) - PROFILE="$HOME/.config/fish/config.fish" - ;; -*/ash) - PROFILE="$HOME/.profile" - ;; -*) - echo "zkup: could not detect shell, manually add ${ZKT_BIN_DIR} to your PATH." - exit 1 - ;; -esac - -if [[ ! -f "$PROFILE" ]]; then - echo "zkup: Profile file $PROFILE does not exist, creating it." - touch "$PROFILE" -fi - -if [[ "$SHELL" == *"/fish"* ]]; then - echo -e "\n# Added by zkup\nfish_add_path -a $ZKT_BIN_DIR" >>"$PROFILE" - echo "zkup: Added $ZKT_BIN_DIR to PATH in $PROFILE using fish_add_path." -else - echo -e "\n# Added by zkup\nexport PATH=\"\$PATH:$ZKT_BIN_DIR\"" >>"$PROFILE" - echo "zkup: Added $ZKT_BIN_DIR to PATH in $PROFILE." -fi - -echo -echo "Added zkup to PATH." -echo "Run 'source $PROFILE' or start a new terminal session to use zkup." -echo "Then run 'zkup' to install ZK Toolbox." diff --git a/zk_toolbox/zkup/zkup b/zk_toolbox/zkup/zkup deleted file mode 100755 index e6ca17487385..000000000000 --- a/zk_toolbox/zkup/zkup +++ /dev/null @@ -1,254 +0,0 @@ -#!/usr/bin/env bash -set -eo pipefail - -BASE_DIR=${XDG_CONFIG_HOME:-$HOME} -ZKT_DIR=${ZKT_DIR:-"$BASE_DIR/.zkt"} -ZKT_BIN_DIR="$ZKT_DIR/bin" - -ZKUP_INSTALL_SUPERVISOR=0 -ZKUP_INSTALL_INCEPTION=0 -ZKUP_ALIAS=0 - -BINS=() - -main() { - parse_args "$@" - - zktoolbox_banner - - check_prerequisites - mkdir -p "$ZKT_BIN_DIR" - - set_bins - - if [ -n "$ZKUP_PATH" ]; then - install_local - else - install_from_repo - fi - - zktoolbox_banner - - for bin in "${BINS[@]}"; do - success "Installed $bin to $ZKT_BIN_DIR/$bin" - done - - if [ $ZKUP_ALIAS -eq 1 ]; then - create_alias - fi -} - -PREREQUISITES=(cargo git) - -check_prerequisites() { - say "Checking prerequisites" - - failed_prerequisites=() - for prerequisite in "${PREREQUISITES[@]}"; do - if ! check_prerequisite "$prerequisite"; then - failed_prerequisites+=("$prerequisite") - fi - done - if [ ${#failed_prerequisites[@]} -gt 0 ]; then - err "The following prerequisites are missing: ${failed_prerequisites[*]}" - exit 1 - fi -} - -check_prerequisite() { - command -v "$1" &>/dev/null -} - -parse_args() { - while [[ $# -gt 0 ]]; do - case $1 in - --) - shift - break - ;; - - -p | --path) - shift - ZKUP_PATH=$1 - ;; - -r | --repo) - shift - ZKUP_REPO=$1 - ;; - -b | --branch) - shift - ZKUP_BRANCH=$1 - ;; - -c | --commit) - shift - ZKUP_COMMIT=$1 - ;; - -v | --version) - shift - ZKUP_VERSION=$1 - ;; - --inception) ZKUP_INSTALL_INCEPTION=1 ;; - --supervisor) ZKUP_INSTALL_SUPERVISOR=1 ;; - -a | --alias) ZKUP_ALIAS=1 ;; - -h | --help) - usage - exit 0 - ;; - *) - err "Unknown argument: $1" - usage - exit 1 - ;; - esac - shift - done -} - -usage() { - cat < Specify a local path to install zk_toolbox from. Ignored if --repo is provided. - -r, --repo GitHub repository to install from (e.g., "matter-labs/zksync-era"). Defaults to "matter-labs/zksync-era". - -b, --branch Git branch to use when installing from a repository. Ignored if --commit or --version is provided. - -c, --commit Git commit hash to use when installing from a repository. Ignored if --branch or --version is provided. - -v, --version Git tag to use when installing from a repository. Ignored if --branch or --commit is provided. - -a, --alias Create aliases zki and zks for zk_inception and zk_supervisor binaries. - --inception Installs the zk_inception binary. Default is to install both zk_inception and zk_supervisor binaries. - --supervisor Installs the zk_supervisor binary. Default is to install both zk_inception and zk_supervisor binaries. - -h, --help Show this help message and exit. - -Examples: - $(basename "$0") --repo matter-labs/zksync-era --version 0.1.1 - $(basename "$0") --path /path/to/local/zk_toolbox --inception -EOF -} - -set_bins() { - if [ $ZKUP_INSTALL_INCEPTION -eq 1 ]; then - BINS+=(zk_inception) - fi - - if [ $ZKUP_INSTALL_SUPERVISOR -eq 1 ]; then - BINS+=(zk_supervisor) - fi - - # Installs both binaries if not option is provided - if [ ${#BINS[@]} -eq 0 ]; then - BINS=(zk_inception zk_supervisor) - fi -} - -install_local() { - if [ ! -d "$ZKUP_PATH/zk_toolbox" ]; then - err "Path $ZKUP_PATH does not contain zk_toolbox" - exit 1 - fi - - if [ -n "$ZKUP_BRANCH" ] || [ -n "$ZKUP_COMMIT" ] || [ -n "$ZKUP_VERSION" ] || [ -n "$ZKUP_REPO" ]; then - warn "Ignoring --repo, --branch, --commit and --version arguments when installing from local path" - fi - - say "Installing zk_toolbox from $ZKUP_PATH" - ensure cd "$ZKUP_PATH"/zk_toolbox - - for bin in "${BINS[@]}"; do - say "Installing $bin" - ensure cargo install --root $ZKT_DIR --path ./crates/$bin --force - done -} - -install_from_repo() { - if [ -n "$ZKUP_PATH" ]; then - warn "Ignoring --path argument when installing from repository" - fi - - ZKUP_REPO=${ZKUP_REPO:-"matter-labs/zksync-era"} - - say "Installing zk_toolbox from $ZKUP_REPO" - - if [ -n "$ZKUP_VERSION" ]; then - if [ -n "$ZKUP_COMMIT" ] || [ -n "$ZKUP_BRANCH" ]; then - warn "Ignoring --commit and --branch arguments when installing by version" - fi - ensure cargo install --root $ZKT_DIR --git "https://github.com/$ZKUP_REPO" --tag "zk_toolbox-v$ZKUP_VERSION" --locked "${BINS[@]}" --force - elif [ -n "$ZKUP_COMMIT" ]; then - if [ -n "$ZKUP_BRANCH" ]; then - warn "Ignoring --branch argument when installing by commit" - fi - ensure cargo install --root $ZKT_DIR --git "https://github.com/$ZKUP_REPO" --rev "$ZKUP_COMMIT" --locked "${BINS[@]}" --force - elif [ -n "$ZKUP_BRANCH" ]; then - ensure cargo install --root $ZKT_DIR --git "https://github.com/$ZKUP_REPO" --branch "$ZKUP_BRANCH" --locked "${BINS[@]}" --force - else - ensure cargo install --root $ZKT_DIR --git "https://github.com/$ZKUP_REPO" --locked "${BINS[@]}" --force - fi -} - -create_alias() { - if [[ "${BINS[@]}" =~ "zk_inception" ]]; then - say "Creating alias 'zki' for zk_inception" - ensure ln -sf "$ZKT_BIN_DIR/zk_inception" "$ZKT_BIN_DIR/zki" - fi - - if [[ "${BINS[@]}" =~ "zk_supervisor" ]]; then - say "Creating alias 'zks' for zk_supervisor" - ensure ln -sf "$ZKT_BIN_DIR/zk_supervisor" "$ZKT_BIN_DIR/zks" - fi -} - -ensure() { - if ! "$@"; then - err "command failed: $*" - exit 1 - fi -} - -say() { - local action="${1%% *}" - local rest="${1#"$action" }" - - echo -e "\033[1;32m$action\033[0m $rest" -} - -success() { - echo -e "\033[1;32m$1\033[0m" -} - -warn() { - echo -e "\033[1;33mWARNING: $1\033[0m" -} - -err() { - echo -e "\033[1;31mERROR: $1\033[0m" >&2 -} - -zktoolbox_banner() { - printf ' - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -███████╗██╗ ██╗ ████████╗ ██████╗ ██████╗ ██╗ ██████╗ ██████╗ ██╗ ██╗ -╚══███╔╝██║ ██╔╝ ╚══██╔══╝██╔═══██╗██╔═══██╗██║ ██╔══██╗██╔═══██╗╚██╗██╔╝ - ███╔╝ █████╔╝ ██║ ██║ ██║██║ ██║██║ ██████╔╝██║ ██║ ╚███╔╝ - ███╔╝ ██╔═██╗ ██║ ██║ ██║██║ ██║██║ ██╔══██╗██║ ██║ ██╔██╗ -███████╗██║ ██╗ ██║ ╚██████╔╝╚██████╔╝███████╗██████╔╝╚██████╔╝██╔╝ ██╗ -╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝ - - - A Comprehensive Toolkit for Creating and Managing ZK Stack Chains - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -Repo : https://github.com/matter-labs/zksync-era/ -Docs : https://docs.zksync.io/ -Contribute : https://github.com/matter-labs/zksync-era/pulls - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - -' -} - -main "$@" diff --git a/zk_toolbox/CHANGELOG.md b/zkstack_cli/CHANGELOG.md similarity index 100% rename from zk_toolbox/CHANGELOG.md rename to zkstack_cli/CHANGELOG.md diff --git a/zk_toolbox/Cargo.lock b/zkstack_cli/Cargo.lock similarity index 97% rename from zk_toolbox/Cargo.lock rename to zkstack_cli/Cargo.lock index 77316756c26f..8750de36c753 100644 --- a/zk_toolbox/Cargo.lock +++ b/zkstack_cli/Cargo.lock @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ "gimli", ] @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "async-stream" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" dependencies = [ "async-stream-impl", "futures-core", @@ -172,9 +172,9 @@ dependencies = [ [[package]] name = "async-stream-impl" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", @@ -531,9 +531,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.23" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbb537bb4a30b90362caddba8f360c0a56bc13d3a5570028e7197204cb54a17" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "jobserver", "libc", @@ -579,9 +579,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.18" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3" +checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", "clap_derive", @@ -598,9 +598,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.18" +version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b" +checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" dependencies = [ "anstream", "anstyle", @@ -1883,9 +1883,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -1898,9 +1898,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -1908,15 +1908,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -1936,9 +1936,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-locks" @@ -1952,9 +1952,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -1963,15 +1963,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" @@ -1985,9 +1985,9 @@ dependencies = [ [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -2036,9 +2036,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.31.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "git_version_macro" @@ -2099,7 +2099,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.5.0", + "indexmap 2.6.0", "slab", "tokio", "tokio-util", @@ -2118,7 +2118,7 @@ dependencies = [ "futures-core", "futures-sink", "http 1.1.0", - "indexmap 2.5.0", + "indexmap 2.6.0", "slab", "tokio", "tokio-util", @@ -2141,6 +2141,12 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + [[package]] name = "hashers" version = "1.0.1" @@ -2273,9 +2279,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] name = "httpdate" @@ -2368,7 +2374,7 @@ dependencies = [ "http 1.1.0", "hyper 1.4.1", "hyper-util", - "rustls 0.23.13", + "rustls 0.23.14", "rustls-pki-types", "tokio", "tokio-rustls 0.26.0", @@ -2531,12 +2537,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown 0.15.0", ] [[package]] @@ -2572,9 +2578,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.10.0" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" [[package]] name = "is_terminal_polyfill" @@ -2635,9 +2641,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.70" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +checksum = "0cb94a0ffd3f3ee755c20f7d8752f45cac88605a4dcf808abcff72873296ec7b" dependencies = [ "wasm-bindgen", ] @@ -3157,21 +3163,18 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "object" -version = "0.36.4" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.20.1" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" -dependencies = [ - "portable-atomic", -] +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "open-fastrlp" @@ -3503,7 +3506,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.5.0", + "indexmap 2.6.0", ] [[package]] @@ -3571,18 +3574,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" dependencies = [ "proc-macro2", "quote", @@ -3720,9 +3723,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -3827,7 +3830,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.13.0", "proc-macro2", "quote", "syn 2.0.79", @@ -4104,7 +4107,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls-pemfile 2.1.3", + "rustls-pemfile 2.2.0", "serde", "serde_json", "serde_urlencoded", @@ -4276,9 +4279,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.13" +version = "0.23.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", "rustls-pki-types", @@ -4298,11 +4301,10 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "2.1.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" dependencies = [ - "base64 0.22.1", "rustls-pki-types", ] @@ -4389,9 +4391,9 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" dependencies = [ "windows-sys 0.59.0", ] @@ -4723,7 +4725,7 @@ version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "itoa", "ryu", "serde", @@ -5004,7 +5006,7 @@ dependencies = [ "hashbrown 0.14.5", "hashlink", "hex", - "indexmap 2.5.0", + "indexmap 2.6.0", "log", "memchr", "once_cell", @@ -5179,7 +5181,7 @@ dependencies = [ "enum_dispatch", "fancy-regex", "getrandom", - "indexmap 2.5.0", + "indexmap 2.6.0", "itertools 0.13.0", "lazy-regex", "nohash-hasher", @@ -5208,7 +5210,7 @@ dependencies = [ "ahash", "enum_dispatch", "fancy-regex", - "indexmap 2.5.0", + "indexmap 2.6.0", "itertools 0.13.0", "nohash-hasher", "pretty_assertions", @@ -5440,12 +5442,12 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +checksum = "4f599bd7ca042cfdf8f4512b277c02ba102247820f9d9d4a9f521f496751a6ef" dependencies = [ "rustix", - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -5628,7 +5630,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.13", + "rustls 0.23.14", "rustls-pki-types", "tokio", ] @@ -5699,7 +5701,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "toml_datetime", "winnow 0.5.40", ] @@ -5710,7 +5712,7 @@ version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "serde", "serde_spanned", "toml_datetime", @@ -5979,9 +5981,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-ident" @@ -6006,9 +6008,9 @@ dependencies = [ [[package]] name = "unicode-properties" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ea75f83c0137a9b98608359a5f1af8144876eb67bcb1ce837368e906a9f524" +checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" [[package]] name = "unicode-width" @@ -6192,9 +6194,9 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "ef073ced962d62984fb38a36e5fdc1a2b23c9e0e1fa0689bb97afa4202ef6887" dependencies = [ "cfg-if", "once_cell", @@ -6203,9 +6205,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "c4bfab14ef75323f4eb75fa52ee0a3fb59611977fd3240da19b2cf36ff85030e" dependencies = [ "bumpalo", "log", @@ -6218,9 +6220,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.43" +version = "0.4.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +checksum = "65471f79c1022ffa5291d33520cbbb53b7687b01c2f8e83b57d102eed7ed479d" dependencies = [ "cfg-if", "js-sys", @@ -6230,9 +6232,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "a7bec9830f60924d9ceb3ef99d55c155be8afa76954edffbb5936ff4509474e7" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -6240,9 +6242,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "4c74f6e152a76a2ad448e223b0fc0b6b5747649c3d769cc6bf45737bf97d0ed6" dependencies = [ "proc-macro2", "quote", @@ -6253,15 +6255,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "a42f6c679374623f295a8623adfe63d9284091245c3504bde47c17a3ce2777d9" [[package]] name = "web-sys" -version = "0.3.70" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +checksum = "44188d185b5bdcae1052d08bcbcf9091a5524038d4572cc4f4f2bb9d5554ddd9" dependencies = [ "js-sys", "wasm-bindgen", @@ -6315,7 +6317,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -6685,10 +6687,26 @@ dependencies = [ ] [[package]] -name = "zk_inception" +name = "zkevm_opcode_defs" +version = "0.132.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0769f7b27d8fb06e715da3290c575cac5d04d10a557faef180e847afce50ac4" +dependencies = [ + "bitflags 2.6.0", + "blake2", + "ethereum-types", + "k256 0.11.6", + "lazy_static", + "sha2_ce", + "sha3_ce", +] + +[[package]] +name = "zkstack" version = "0.1.0" dependencies = [ "anyhow", + "chrono", "clap", "clap-markdown", "cliclack", @@ -6696,6 +6714,7 @@ dependencies = [ "config", "ethers", "eyre", + "futures", "human-panic", "lazy_static", "prost 0.12.6", @@ -6706,6 +6725,7 @@ dependencies = [ "serde_json", "serde_yaml", "slugify-rs", + "sqruff-lib", "strum", "thiserror", "tokio", @@ -6723,46 +6743,6 @@ dependencies = [ "zksync_protobuf_config", ] -[[package]] -name = "zk_supervisor" -version = "0.1.0" -dependencies = [ - "anyhow", - "chrono", - "clap", - "clap-markdown", - "common", - "config", - "ethers", - "futures", - "human-panic", - "serde", - "serde_json", - "serde_yaml", - "sqruff-lib", - "strum", - "tokio", - "types", - "url", - "xshell", - "zksync_basic_types", -] - -[[package]] -name = "zkevm_opcode_defs" -version = "0.132.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0769f7b27d8fb06e715da3290c575cac5d04d10a557faef180e847afce50ac4" -dependencies = [ - "bitflags 2.6.0", - "blake2", - "ethereum-types", - "k256 0.11.6", - "lazy_static", - "sha2_ce", - "sha3_ce", -] - [[package]] name = "zksync_basic_types" version = "0.1.0" diff --git a/zk_toolbox/Cargo.toml b/zkstack_cli/Cargo.toml similarity index 90% rename from zk_toolbox/Cargo.toml rename to zkstack_cli/Cargo.toml index cb442a6182e6..a805cf85d518 100644 --- a/zk_toolbox/Cargo.toml +++ b/zkstack_cli/Cargo.toml @@ -3,8 +3,7 @@ members = [ "crates/common", "crates/config", "crates/types", - "crates/zk_inception", - "crates/zk_supervisor", + "crates/zkstack", "crates/git_version_macro", ] resolver = "2" @@ -16,8 +15,8 @@ homepage = "https://zksync.io/" license = "MIT OR Apache-2.0" authors = ["The Matter Labs Team "] exclude = ["./github"] -repository = "https://github.com/matter-labs/zk_toolbox/" -description = "ZK Toolbox is a set of tools for working with zk stack." +repository = "https://github.com/matter-labs/zksync-era/tree/main/zkstack_cli/" +description = "ZK Stack CLI is a set of tools for working with zk stack." keywords = ["zk", "cryptography", "blockchain", "ZKStack", "ZKsync"] diff --git a/zk_toolbox/README.md b/zkstack_cli/README.md similarity index 85% rename from zk_toolbox/README.md rename to zkstack_cli/README.md index 6197a79eec99..f1c92cc3d2e3 100644 --- a/zk_toolbox/README.md +++ b/zkstack_cli/README.md @@ -1,11 +1,7 @@ -# zk_toolbox +# ZK Stack CLI -Toolkit for creating and managing ZK Stack chains. - -## ZK Inception - -`ZK Inception` facilitates the creation and management of ZK Stacks. Commands are interactive but can also accept -arguments via the command line. +Toolkit for creating and managing ZK Stack chains. `ZK Stack CLI` facilitates the creation and management of ZK Stacks. +Commands are interactive but can also accept arguments via the command line. ### Dependencies @@ -14,19 +10,25 @@ dependencies on your machine. Ignore the Environment section for now. ### Installation -Install `zk_inception` from Git: +You can use `zkstackup` to install and manage `zkstack`: + +```bash +curl -L https://raw.githubusercontent.com/matter-labs/zksync-era/main/zkstack_cli/zkstackup/install | bash +``` + +Then install the most recent version with: ```bash -cargo install --git https://github.com/matter-labs/zksync-era/ --locked zk_inception zk_supervisor --force +zkstackup ``` Or manually build from a local copy of the [ZKsync](https://github.com/matter-labs/zksync-era/) repository: ```bash -./bin/zkt +zkstackup --local ``` -This command installs `zk_inception` and `zk_supervisor` from the current repository. +This command installs `zkstack` from the current repository. ### Foundry Integration @@ -51,13 +53,13 @@ BridgeHub, shared bridges, and state transition managers. To create a ZK Stack project, start by creating an ecosystem: ```bash -zk_inception ecosystem create +zkstack ecosystem create ``` If you choose not to start database & L1 containers after creating the ecosystem, you can later run: ```bash -zk_inception containers +zkstack containers ``` Execute subsequent commands from within the created ecosystem folder: @@ -71,14 +73,14 @@ cd path/to/ecosystem/name If the ecosystem has never been deployed before, initialize it: ```bash -zk_inception ecosystem init +zkstack ecosystem init ``` This initializes the first ZK chain, which becomes the default. Override with `--chain ` if needed. For default params, use: ```bash -zk_inception ecosystem init --dev +zkstack ecosystem init --dev ``` If the process gets stuck, resume it with `--resume`. This flag keeps track of already sent transactions and sends new @@ -98,7 +100,7 @@ To verify contracts, use the `--verify` flag. To change the default ZK chain: ```bash -zk_inception ecosystem change-default-chain +zkstack ecosystem change-default-chain ``` IMPORTANT: Currently, you cannot use an existing ecosystem to register a new chain. This feature will be added in the @@ -109,19 +111,19 @@ future. To setup [era-observability](https://github.com/matter-labs/era-observability): ```bash -zk_inception ecosystem setup-observability +zkstack ecosystem setup-observability ``` Or run: ```bash -zk_inception ecosystem init --observability +zkstack ecosystem init --observability ``` To start observability containers: ```bash -zk_inception containers --observability +zkstack containers --observability ``` ### ZK Chain @@ -131,7 +133,7 @@ zk_inception containers --observability The first ZK chain is generated upon ecosystem creation. Create additional chains and switch between them: ```bash -zk_inception chain create +zkstack chain create ``` #### Init @@ -139,7 +141,7 @@ zk_inception chain create Deploy contracts and initialize Zk Chain: ```bash -zk_inception chain init +zkstack chain init ``` This registers the chain in the BridgeHub and deploys all necessary contracts. Manual initialization steps: @@ -154,7 +156,7 @@ by a third party). To run the chain: ```bash -zk_inception server +zkstack server ``` You can specify the component you want to run using `--components` flag @@ -180,13 +182,13 @@ information. Initialize the prover: ```bash -zk_inception prover init +zkstack prover init ``` Run the prover: ```bash -zk_inception prover run +zkstack prover run ``` Specify the prover component with `--component `. Components: @@ -202,13 +204,13 @@ For `witness-generator`, specify the round with `--round `. Rounds: Download required binaries (`solc`, `zksolc`, `vyper`, `zkvyper`): ```bash -zk_inception contract-verifier init +zkstack contract-verifier init ``` Run the contract verifier: ```bash -zk_inception contract-verifier run +zkstack contract-verifier run ``` ### External Node @@ -220,7 +222,7 @@ Commands for running an external node: Prepare configs: ```bash -zk_inception en configs +zkstack en configs ``` This ensures no port conflicts with the main node. @@ -230,7 +232,7 @@ This ensures no port conflicts with the main node. Prepare the databases: ```bash -zk_inception en init +zkstack en init ``` #### Run @@ -238,7 +240,7 @@ zk_inception en init Run the external node: ```bash -zk_inception en run +zkstack en run ``` ### Portal @@ -247,7 +249,7 @@ Once you have at least one chain initialized, you can run the [portal](https://g web-app to bridge tokens between L1 and L2 and more: ```bash -zk_inception portal +zkstack portal ``` This command will start the dockerized portal app using configuration from `apps/portal.config.json` file inside your @@ -263,7 +265,7 @@ contracts and more. First, each chain should be initialized: ```bash -zk_inception explorer init +zkstack explorer init ``` This command creates a database to store explorer data and generatesdocker compose file with explorer services @@ -272,7 +274,7 @@ This command creates a database to store explorer data and generatesdocker compo Next, for each chain you want to have an explorer, you need to start its backend services: ```bash -zk_inception explorer backend --chain +zkstack explorer backend --chain ``` This command uses previously created docker compose file to start the services (api, data fetcher, worker) required for @@ -281,7 +283,7 @@ the explorer. Finally, you can run the explorer app: ```bash -zk_inception explorer run +zkstack explorer run ``` This command will start the dockerized explorer app using configuration from `apps/explorer.config.json` file inside @@ -293,22 +295,22 @@ your ecosystem directory. You can edit this file to configure the app if needed. To update your node: ```bash -zk_inception update +zkstack update ``` This command pulls the latest changes, syncs the general config for all chains, and raises a warning if L1 upgrades are needed. -## ZK Supervisor +## Dev -Tools for developing ZKsync. +The subcommand `zkstack dev` offers tools for developing ZKsync. ### Database Commands for database manipulation: ```bash -zk_supervisor db +zkstack dev db ``` Possible commands: @@ -326,7 +328,7 @@ Possible commands: Clean artifacts: ```bash -zk_supervisor clean +zkstack dev clean ``` Possible commands: @@ -340,7 +342,7 @@ Possible commands: Run ZKsync tests: ```bash -zk_supervisor test +zkstack dev test ``` Possible commands: @@ -358,7 +360,7 @@ Possible commands: Create a snapshot of the current chain: ```bash -zks snapshot create +zkstack dev snapshot create ``` ### Contracts @@ -366,7 +368,7 @@ zks snapshot create Build contracts: ```bash -zks contracts +zkstack dev contracts ``` ### Format @@ -374,7 +376,7 @@ zks contracts Format code: ```bash -zks fmt +zkstack dev fmt ``` By default, this command runs all formatters. To run a specific fomatter use the following subcommands: @@ -388,7 +390,7 @@ By default, this command runs all formatters. To run a specific fomatter use the Lint code: ```bash -zks lint +zkstack dev lint ``` By default, this command runs the linter on all files. To target specific file types, use the `--target` option. diff --git a/zk_toolbox/crates/common/Cargo.toml b/zkstack_cli/crates/common/Cargo.toml similarity index 100% rename from zk_toolbox/crates/common/Cargo.toml rename to zkstack_cli/crates/common/Cargo.toml diff --git a/zk_toolbox/crates/common/src/cmd.rs b/zkstack_cli/crates/common/src/cmd.rs similarity index 100% rename from zk_toolbox/crates/common/src/cmd.rs rename to zkstack_cli/crates/common/src/cmd.rs diff --git a/zk_toolbox/crates/common/src/config.rs b/zkstack_cli/crates/common/src/config.rs similarity index 100% rename from zk_toolbox/crates/common/src/config.rs rename to zkstack_cli/crates/common/src/config.rs diff --git a/zk_toolbox/crates/common/src/contracts.rs b/zkstack_cli/crates/common/src/contracts.rs similarity index 100% rename from zk_toolbox/crates/common/src/contracts.rs rename to zkstack_cli/crates/common/src/contracts.rs diff --git a/zk_toolbox/crates/common/src/db.rs b/zkstack_cli/crates/common/src/db.rs similarity index 100% rename from zk_toolbox/crates/common/src/db.rs rename to zkstack_cli/crates/common/src/db.rs diff --git a/zk_toolbox/crates/common/src/docker.rs b/zkstack_cli/crates/common/src/docker.rs similarity index 100% rename from zk_toolbox/crates/common/src/docker.rs rename to zkstack_cli/crates/common/src/docker.rs diff --git a/zk_toolbox/crates/common/src/ethereum.rs b/zkstack_cli/crates/common/src/ethereum.rs similarity index 100% rename from zk_toolbox/crates/common/src/ethereum.rs rename to zkstack_cli/crates/common/src/ethereum.rs diff --git a/zk_toolbox/crates/common/src/external_node.rs b/zkstack_cli/crates/common/src/external_node.rs similarity index 100% rename from zk_toolbox/crates/common/src/external_node.rs rename to zkstack_cli/crates/common/src/external_node.rs diff --git a/zk_toolbox/crates/common/src/files.rs b/zkstack_cli/crates/common/src/files.rs similarity index 100% rename from zk_toolbox/crates/common/src/files.rs rename to zkstack_cli/crates/common/src/files.rs diff --git a/zk_toolbox/crates/common/src/forge.rs b/zkstack_cli/crates/common/src/forge.rs similarity index 99% rename from zk_toolbox/crates/common/src/forge.rs rename to zkstack_cli/crates/common/src/forge.rs index e573e492aa4f..bef285fb89b2 100644 --- a/zk_toolbox/crates/common/src/forge.rs +++ b/zkstack_cli/crates/common/src/forge.rs @@ -278,7 +278,7 @@ pub struct ForgeScriptArgs { pub resume: bool, /// List of additional arguments that can be passed through the CLI. /// - /// e.g.: `zk_inception init -a --private-key=` + /// e.g.: `zkstack init -a --private-key=` #[clap(long, short)] #[arg(trailing_var_arg = true, allow_hyphen_values = true, hide = false)] additional_args: Vec, diff --git a/zk_toolbox/crates/common/src/git.rs b/zkstack_cli/crates/common/src/git.rs similarity index 100% rename from zk_toolbox/crates/common/src/git.rs rename to zkstack_cli/crates/common/src/git.rs diff --git a/zk_toolbox/crates/common/src/lib.rs b/zkstack_cli/crates/common/src/lib.rs similarity index 100% rename from zk_toolbox/crates/common/src/lib.rs rename to zkstack_cli/crates/common/src/lib.rs diff --git a/zk_toolbox/crates/common/src/prerequisites.rs b/zkstack_cli/crates/common/src/prerequisites.rs similarity index 100% rename from zk_toolbox/crates/common/src/prerequisites.rs rename to zkstack_cli/crates/common/src/prerequisites.rs diff --git a/zk_toolbox/crates/common/src/prompt/confirm.rs b/zkstack_cli/crates/common/src/prompt/confirm.rs similarity index 100% rename from zk_toolbox/crates/common/src/prompt/confirm.rs rename to zkstack_cli/crates/common/src/prompt/confirm.rs diff --git a/zk_toolbox/crates/common/src/prompt/input.rs b/zkstack_cli/crates/common/src/prompt/input.rs similarity index 100% rename from zk_toolbox/crates/common/src/prompt/input.rs rename to zkstack_cli/crates/common/src/prompt/input.rs diff --git a/zk_toolbox/crates/common/src/prompt/mod.rs b/zkstack_cli/crates/common/src/prompt/mod.rs similarity index 100% rename from zk_toolbox/crates/common/src/prompt/mod.rs rename to zkstack_cli/crates/common/src/prompt/mod.rs diff --git a/zk_toolbox/crates/common/src/prompt/select.rs b/zkstack_cli/crates/common/src/prompt/select.rs similarity index 100% rename from zk_toolbox/crates/common/src/prompt/select.rs rename to zkstack_cli/crates/common/src/prompt/select.rs diff --git a/zk_toolbox/crates/common/src/server.rs b/zkstack_cli/crates/common/src/server.rs similarity index 100% rename from zk_toolbox/crates/common/src/server.rs rename to zkstack_cli/crates/common/src/server.rs diff --git a/zk_toolbox/crates/common/src/term/error.rs b/zkstack_cli/crates/common/src/term/error.rs similarity index 100% rename from zk_toolbox/crates/common/src/term/error.rs rename to zkstack_cli/crates/common/src/term/error.rs diff --git a/zk_toolbox/crates/common/src/term/logger.rs b/zkstack_cli/crates/common/src/term/logger.rs similarity index 97% rename from zk_toolbox/crates/common/src/term/logger.rs rename to zkstack_cli/crates/common/src/term/logger.rs index 17e518d9ad92..035e81dc1355 100644 --- a/zk_toolbox/crates/common/src/term/logger.rs +++ b/zkstack_cli/crates/common/src/term/logger.rs @@ -14,7 +14,7 @@ fn term_write(msg: impl Display) { } pub fn intro() { - cliclak_intro(style(" ZKsync toolbox ").on_cyan().black()).unwrap(); + cliclak_intro(style(" ZK Stack CLI ").on_cyan().black()).unwrap(); } pub fn outro(msg: impl Display) { diff --git a/zk_toolbox/crates/common/src/term/mod.rs b/zkstack_cli/crates/common/src/term/mod.rs similarity index 100% rename from zk_toolbox/crates/common/src/term/mod.rs rename to zkstack_cli/crates/common/src/term/mod.rs diff --git a/zk_toolbox/crates/common/src/term/spinner.rs b/zkstack_cli/crates/common/src/term/spinner.rs similarity index 100% rename from zk_toolbox/crates/common/src/term/spinner.rs rename to zkstack_cli/crates/common/src/term/spinner.rs diff --git a/zk_toolbox/crates/common/src/version.rs b/zkstack_cli/crates/common/src/version.rs similarity index 100% rename from zk_toolbox/crates/common/src/version.rs rename to zkstack_cli/crates/common/src/version.rs diff --git a/zk_toolbox/crates/common/src/wallets.rs b/zkstack_cli/crates/common/src/wallets.rs similarity index 100% rename from zk_toolbox/crates/common/src/wallets.rs rename to zkstack_cli/crates/common/src/wallets.rs diff --git a/zk_toolbox/crates/common/src/yaml.rs b/zkstack_cli/crates/common/src/yaml.rs similarity index 100% rename from zk_toolbox/crates/common/src/yaml.rs rename to zkstack_cli/crates/common/src/yaml.rs diff --git a/zk_toolbox/crates/config/Cargo.toml b/zkstack_cli/crates/config/Cargo.toml similarity index 100% rename from zk_toolbox/crates/config/Cargo.toml rename to zkstack_cli/crates/config/Cargo.toml diff --git a/zk_toolbox/crates/config/src/apps.rs b/zkstack_cli/crates/config/src/apps.rs similarity index 96% rename from zk_toolbox/crates/config/src/apps.rs rename to zkstack_cli/crates/config/src/apps.rs index 697b35b0851b..3bd611bdc32a 100644 --- a/zk_toolbox/crates/config/src/apps.rs +++ b/zkstack_cli/crates/config/src/apps.rs @@ -5,7 +5,7 @@ use xshell::Shell; use crate::{ consts::{APPS_CONFIG_FILE, DEFAULT_EXPLORER_PORT, DEFAULT_PORTAL_PORT, LOCAL_CONFIGS_PATH}, - traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, ZkToolboxConfig}, + traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, ZkStackConfig}, }; /// Ecosystem level configuration for the apps (portal and explorer). @@ -20,7 +20,7 @@ pub struct AppEcosystemConfig { pub http_port: u16, } -impl ZkToolboxConfig for AppsEcosystemConfig {} +impl ZkStackConfig for AppsEcosystemConfig {} impl FileConfigWithDefaultName for AppsEcosystemConfig { const FILE_NAME: &'static str = APPS_CONFIG_FILE; } diff --git a/zk_toolbox/crates/config/src/chain.rs b/zkstack_cli/crates/config/src/chain.rs similarity index 98% rename from zk_toolbox/crates/config/src/chain.rs rename to zkstack_cli/crates/config/src/chain.rs index d6b6e2b866b7..6c82d6ef3c37 100644 --- a/zk_toolbox/crates/config/src/chain.rs +++ b/zkstack_cli/crates/config/src/chain.rs @@ -16,7 +16,7 @@ use crate::{ create_localhost_wallets, traits::{ FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig, - SaveConfigWithBasePath, ZkToolboxConfig, + SaveConfigWithBasePath, ZkStackConfig, }, ContractsConfig, GeneralConfig, GenesisConfig, SecretsConfig, WalletsConfig, }; @@ -165,4 +165,4 @@ impl FileConfigWithDefaultName for ChainConfigInternal { const FILE_NAME: &'static str = CONFIG_NAME; } -impl ZkToolboxConfig for ChainConfigInternal {} +impl ZkStackConfig for ChainConfigInternal {} diff --git a/zk_toolbox/crates/config/src/consensus_config.rs b/zkstack_cli/crates/config/src/consensus_config.rs similarity index 100% rename from zk_toolbox/crates/config/src/consensus_config.rs rename to zkstack_cli/crates/config/src/consensus_config.rs diff --git a/zk_toolbox/crates/config/src/consensus_secrets.rs b/zkstack_cli/crates/config/src/consensus_secrets.rs similarity index 100% rename from zk_toolbox/crates/config/src/consensus_secrets.rs rename to zkstack_cli/crates/config/src/consensus_secrets.rs diff --git a/zk_toolbox/crates/config/src/consts.rs b/zkstack_cli/crates/config/src/consts.rs similarity index 97% rename from zk_toolbox/crates/config/src/consts.rs rename to zkstack_cli/crates/config/src/consts.rs index 80b204cc6191..f462ce33b8f8 100644 --- a/zk_toolbox/crates/config/src/consts.rs +++ b/zkstack_cli/crates/config/src/consts.rs @@ -62,8 +62,6 @@ pub const DEFAULT_EXPLORER_WORKER_PORT: u16 = 3001; pub const DEFAULT_EXPLORER_API_PORT: u16 = 3002; /// Default port for the explorer data fetcher service pub const DEFAULT_EXPLORER_DATA_FETCHER_PORT: u16 = 3040; -/// Default port for consensus service -pub const DEFAULT_CONSENSUS_PORT: u16 = 3054; pub const EXPLORER_API_DOCKER_IMAGE: &str = "matterlabs/block-explorer-api"; pub const EXPLORER_DATA_FETCHER_DOCKER_IMAGE: &str = "matterlabs/block-explorer-data-fetcher"; diff --git a/zk_toolbox/crates/config/src/contracts.rs b/zkstack_cli/crates/config/src/contracts.rs similarity index 97% rename from zk_toolbox/crates/config/src/contracts.rs rename to zkstack_cli/crates/config/src/contracts.rs index 8296aa188527..e6676989e68c 100644 --- a/zk_toolbox/crates/config/src/contracts.rs +++ b/zkstack_cli/crates/config/src/contracts.rs @@ -11,7 +11,7 @@ use crate::{ }, register_chain::output::RegisterChainOutput, }, - traits::{FileConfigWithDefaultName, ZkToolboxConfig}, + traits::{FileConfigWithDefaultName, ZkStackConfig}, }; #[derive(Debug, Deserialize, Serialize, Clone, Default)] @@ -114,7 +114,7 @@ impl FileConfigWithDefaultName for ContractsConfig { const FILE_NAME: &'static str = CONTRACTS_FILE; } -impl ZkToolboxConfig for ContractsConfig {} +impl ZkStackConfig for ContractsConfig {} #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)] pub struct EcosystemContracts { @@ -125,7 +125,7 @@ pub struct EcosystemContracts { pub diamond_cut_data: String, } -impl ZkToolboxConfig for EcosystemContracts {} +impl ZkStackConfig for EcosystemContracts {} #[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct BridgesContracts { diff --git a/zk_toolbox/crates/config/src/docker_compose.rs b/zkstack_cli/crates/config/src/docker_compose.rs similarity index 94% rename from zk_toolbox/crates/config/src/docker_compose.rs rename to zkstack_cli/crates/config/src/docker_compose.rs index 05c6e73eaea5..2208c5a8654e 100644 --- a/zk_toolbox/crates/config/src/docker_compose.rs +++ b/zkstack_cli/crates/config/src/docker_compose.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; -use crate::traits::ZkToolboxConfig; +use crate::traits::ZkStackConfig; #[derive(Debug, Default, Serialize, Deserialize, Clone)] pub struct DockerComposeConfig { @@ -34,7 +34,7 @@ pub struct DockerComposeService { pub other: serde_json::Value, } -impl ZkToolboxConfig for DockerComposeConfig {} +impl ZkStackConfig for DockerComposeConfig {} impl DockerComposeConfig { pub fn add_service(&mut self, name: &str, service: DockerComposeService) { diff --git a/zk_toolbox/crates/config/src/ecosystem.rs b/zkstack_cli/crates/config/src/ecosystem.rs similarity index 98% rename from zk_toolbox/crates/config/src/ecosystem.rs rename to zkstack_cli/crates/config/src/ecosystem.rs index 7ac81cd53941..79cb1c4ea27d 100644 --- a/zk_toolbox/crates/config/src/ecosystem.rs +++ b/zkstack_cli/crates/config/src/ecosystem.rs @@ -21,7 +21,7 @@ use crate::{ input::{Erc20DeploymentConfig, InitialDeploymentConfig}, output::{ERC20Tokens, Erc20Token}, }, - traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, ZkToolboxConfig}, + traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, ZkStackConfig}, ChainConfig, ChainConfigInternal, ContractsConfig, WalletsConfig, }; @@ -94,9 +94,9 @@ impl FileConfigWithDefaultName for EcosystemConfig { const FILE_NAME: &'static str = CONFIG_NAME; } -impl ZkToolboxConfig for EcosystemConfigInternal {} +impl ZkStackConfig for EcosystemConfigInternal {} -impl ZkToolboxConfig for EcosystemConfig {} +impl ZkStackConfig for EcosystemConfig {} impl EcosystemConfig { fn get_shell(&self) -> &Shell { diff --git a/zk_toolbox/crates/config/src/explorer.rs b/zkstack_cli/crates/config/src/explorer.rs similarity index 98% rename from zk_toolbox/crates/config/src/explorer.rs rename to zkstack_cli/crates/config/src/explorer.rs index ee7a59e5105c..7ce9b986a1eb 100644 --- a/zk_toolbox/crates/config/src/explorer.rs +++ b/zkstack_cli/crates/config/src/explorer.rs @@ -8,7 +8,7 @@ use crate::{ EXPLORER_CONFIG_FILE, EXPLORER_JS_CONFIG_FILE, LOCAL_APPS_PATH, LOCAL_CONFIGS_PATH, LOCAL_GENERATED_PATH, }, - traits::{ReadConfig, SaveConfig, ZkToolboxConfig}, + traits::{ReadConfig, SaveConfig, ZkStackConfig}, }; /// Explorer JSON configuration file. This file contains configuration for the explorer app. @@ -144,4 +144,4 @@ impl Default for ExplorerConfig { } } -impl ZkToolboxConfig for ExplorerConfig {} +impl ZkStackConfig for ExplorerConfig {} diff --git a/zk_toolbox/crates/config/src/explorer_compose.rs b/zkstack_cli/crates/config/src/explorer_compose.rs similarity index 98% rename from zk_toolbox/crates/config/src/explorer_compose.rs rename to zkstack_cli/crates/config/src/explorer_compose.rs index ca9abc1e3e23..13dd665d2e3d 100644 --- a/zk_toolbox/crates/config/src/explorer_compose.rs +++ b/zkstack_cli/crates/config/src/explorer_compose.rs @@ -16,7 +16,7 @@ use crate::{ EXPLORER_WORKER_DOCKER_IMAGE, LOCAL_CHAINS_PATH, LOCAL_CONFIGS_PATH, }, docker_compose::{DockerComposeConfig, DockerComposeService}, - traits::ZkToolboxConfig, + traits::ZkStackConfig, EXPLORER_BATCHES_PROCESSING_POLLING_INTERVAL, }; @@ -72,7 +72,7 @@ pub struct ExplorerBackendComposeConfig { pub docker_compose: DockerComposeConfig, } -impl ZkToolboxConfig for ExplorerBackendComposeConfig {} +impl ZkStackConfig for ExplorerBackendComposeConfig {} impl ExplorerBackendComposeConfig { const API_NAME: &'static str = "api"; diff --git a/zk_toolbox/crates/config/src/external_node.rs b/zkstack_cli/crates/config/src/external_node.rs similarity index 100% rename from zk_toolbox/crates/config/src/external_node.rs rename to zkstack_cli/crates/config/src/external_node.rs diff --git a/zk_toolbox/crates/config/src/file_config.rs b/zkstack_cli/crates/config/src/file_config.rs similarity index 100% rename from zk_toolbox/crates/config/src/file_config.rs rename to zkstack_cli/crates/config/src/file_config.rs diff --git a/zk_toolbox/crates/config/src/forge_interface/accept_ownership/mod.rs b/zkstack_cli/crates/config/src/forge_interface/accept_ownership/mod.rs similarity index 71% rename from zk_toolbox/crates/config/src/forge_interface/accept_ownership/mod.rs rename to zkstack_cli/crates/config/src/forge_interface/accept_ownership/mod.rs index 636cffc49f89..4f73483b393a 100644 --- a/zk_toolbox/crates/config/src/forge_interface/accept_ownership/mod.rs +++ b/zkstack_cli/crates/config/src/forge_interface/accept_ownership/mod.rs @@ -1,9 +1,9 @@ use ethers::types::Address; use serde::{Deserialize, Serialize}; -use crate::traits::ZkToolboxConfig; +use crate::traits::ZkStackConfig; -impl ZkToolboxConfig for AcceptOwnershipInput {} +impl ZkStackConfig for AcceptOwnershipInput {} #[derive(Debug, Deserialize, Serialize, Clone)] pub struct AcceptOwnershipInput { diff --git a/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/input.rs b/zkstack_cli/crates/config/src/forge_interface/deploy_ecosystem/input.rs similarity index 97% rename from zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/input.rs rename to zkstack_cli/crates/config/src/forge_interface/deploy_ecosystem/input.rs index 41ce906f455b..d5611f805b17 100644 --- a/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/input.rs +++ b/zkstack_cli/crates/config/src/forge_interface/deploy_ecosystem/input.rs @@ -10,7 +10,7 @@ use zksync_basic_types::L2ChainId; use crate::{ consts::INITIAL_DEPLOYMENT_FILE, - traits::{FileConfigWithDefaultName, ZkToolboxConfig}, + traits::{FileConfigWithDefaultName, ZkStackConfig}, ContractsConfig, GenesisConfig, WalletsConfig, }; @@ -61,7 +61,7 @@ impl FileConfigWithDefaultName for InitialDeploymentConfig { const FILE_NAME: &'static str = INITIAL_DEPLOYMENT_FILE; } -impl ZkToolboxConfig for InitialDeploymentConfig {} +impl ZkStackConfig for InitialDeploymentConfig {} #[derive(Debug, Deserialize, Serialize, Clone)] pub struct Erc20DeploymentConfig { @@ -72,7 +72,7 @@ impl FileConfigWithDefaultName for Erc20DeploymentConfig { const FILE_NAME: &'static str = INITIAL_DEPLOYMENT_FILE; } -impl ZkToolboxConfig for Erc20DeploymentConfig {} +impl ZkStackConfig for Erc20DeploymentConfig {} impl Default for Erc20DeploymentConfig { fn default() -> Self { @@ -115,7 +115,7 @@ pub struct DeployL1Config { pub tokens: TokensDeployL1Config, } -impl ZkToolboxConfig for DeployL1Config {} +impl ZkStackConfig for DeployL1Config {} impl DeployL1Config { pub fn new( @@ -212,7 +212,7 @@ pub struct DeployErc20Config { pub additional_addresses_for_minting: Vec
, } -impl ZkToolboxConfig for DeployErc20Config {} +impl ZkStackConfig for DeployErc20Config {} impl DeployErc20Config { pub fn new( diff --git a/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/mod.rs b/zkstack_cli/crates/config/src/forge_interface/deploy_ecosystem/mod.rs similarity index 100% rename from zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/mod.rs rename to zkstack_cli/crates/config/src/forge_interface/deploy_ecosystem/mod.rs diff --git a/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/output.rs b/zkstack_cli/crates/config/src/forge_interface/deploy_ecosystem/output.rs similarity index 95% rename from zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/output.rs rename to zkstack_cli/crates/config/src/forge_interface/deploy_ecosystem/output.rs index 7f35cf0357c2..7a922cbdf3c0 100644 --- a/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/output.rs +++ b/zkstack_cli/crates/config/src/forge_interface/deploy_ecosystem/output.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::{ consts::ERC20_CONFIGS_FILE, - traits::{FileConfigWithDefaultName, ZkToolboxConfig}, + traits::{FileConfigWithDefaultName, ZkStackConfig}, }; #[derive(Debug, Deserialize, Serialize, Clone)] @@ -21,7 +21,7 @@ pub struct DeployL1Output { pub deployed_addresses: DeployL1DeployedAddressesOutput, } -impl ZkToolboxConfig for DeployL1Output {} +impl ZkStackConfig for DeployL1Output {} #[derive(Debug, Deserialize, Serialize, Clone)] pub struct DeployL1ContractsConfigOutput { @@ -98,4 +98,4 @@ impl FileConfigWithDefaultName for ERC20Tokens { const FILE_NAME: &'static str = ERC20_CONFIGS_FILE; } -impl ZkToolboxConfig for ERC20Tokens {} +impl ZkStackConfig for ERC20Tokens {} diff --git a/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/input.rs b/zkstack_cli/crates/config/src/forge_interface/deploy_l2_contracts/input.rs similarity index 92% rename from zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/input.rs rename to zkstack_cli/crates/config/src/forge_interface/deploy_l2_contracts/input.rs index b20b58f99c58..3836dca9d24c 100644 --- a/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/input.rs +++ b/zkstack_cli/crates/config/src/forge_interface/deploy_l2_contracts/input.rs @@ -2,9 +2,9 @@ use ethers::types::Address; use serde::{Deserialize, Serialize}; use zksync_basic_types::L2ChainId; -use crate::{traits::ZkToolboxConfig, ChainConfig}; +use crate::{traits::ZkStackConfig, ChainConfig}; -impl ZkToolboxConfig for DeployL2ContractsInput {} +impl ZkStackConfig for DeployL2ContractsInput {} /// Fields corresponding to `contracts/l1-contracts/deploy-script-config-template/config-deploy-l2-config.toml` /// which are read by `contracts/l1-contracts/deploy-scripts/DeployL2Contracts.sol`. diff --git a/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/mod.rs b/zkstack_cli/crates/config/src/forge_interface/deploy_l2_contracts/mod.rs similarity index 100% rename from zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/mod.rs rename to zkstack_cli/crates/config/src/forge_interface/deploy_l2_contracts/mod.rs diff --git a/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/output.rs b/zkstack_cli/crates/config/src/forge_interface/deploy_l2_contracts/output.rs similarity index 73% rename from zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/output.rs rename to zkstack_cli/crates/config/src/forge_interface/deploy_l2_contracts/output.rs index ca5cac12c02d..29be89b91016 100644 --- a/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/output.rs +++ b/zkstack_cli/crates/config/src/forge_interface/deploy_l2_contracts/output.rs @@ -1,12 +1,12 @@ use ethers::types::Address; use serde::{Deserialize, Serialize}; -use crate::traits::ZkToolboxConfig; +use crate::traits::ZkStackConfig; -impl ZkToolboxConfig for InitializeBridgeOutput {} -impl ZkToolboxConfig for DefaultL2UpgradeOutput {} -impl ZkToolboxConfig for ConsensusRegistryOutput {} -impl ZkToolboxConfig for Multicall3Output {} +impl ZkStackConfig for InitializeBridgeOutput {} +impl ZkStackConfig for DefaultL2UpgradeOutput {} +impl ZkStackConfig for ConsensusRegistryOutput {} +impl ZkStackConfig for Multicall3Output {} #[derive(Debug, Clone, Serialize, Deserialize)] pub struct InitializeBridgeOutput { diff --git a/zk_toolbox/crates/config/src/forge_interface/mod.rs b/zkstack_cli/crates/config/src/forge_interface/mod.rs similarity index 100% rename from zk_toolbox/crates/config/src/forge_interface/mod.rs rename to zkstack_cli/crates/config/src/forge_interface/mod.rs diff --git a/zk_toolbox/crates/config/src/forge_interface/paymaster/mod.rs b/zkstack_cli/crates/config/src/forge_interface/paymaster/mod.rs similarity index 83% rename from zk_toolbox/crates/config/src/forge_interface/paymaster/mod.rs rename to zkstack_cli/crates/config/src/forge_interface/paymaster/mod.rs index 9631fe743180..2af7502e0b76 100644 --- a/zk_toolbox/crates/config/src/forge_interface/paymaster/mod.rs +++ b/zkstack_cli/crates/config/src/forge_interface/paymaster/mod.rs @@ -2,7 +2,7 @@ use ethers::types::Address; use serde::{Deserialize, Serialize}; use zksync_basic_types::L2ChainId; -use crate::{traits::ZkToolboxConfig, ChainConfig}; +use crate::{traits::ZkStackConfig, ChainConfig}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct DeployPaymasterInput { @@ -22,11 +22,11 @@ impl DeployPaymasterInput { } } -impl ZkToolboxConfig for DeployPaymasterInput {} +impl ZkStackConfig for DeployPaymasterInput {} #[derive(Debug, Serialize, Deserialize, Clone)] pub struct DeployPaymasterOutput { pub paymaster: Address, } -impl ZkToolboxConfig for DeployPaymasterOutput {} +impl ZkStackConfig for DeployPaymasterOutput {} diff --git a/zk_toolbox/crates/config/src/forge_interface/register_chain/input.rs b/zkstack_cli/crates/config/src/forge_interface/register_chain/input.rs similarity index 96% rename from zk_toolbox/crates/config/src/forge_interface/register_chain/input.rs rename to zkstack_cli/crates/config/src/forge_interface/register_chain/input.rs index e2e60294e867..fb7c606a4569 100644 --- a/zk_toolbox/crates/config/src/forge_interface/register_chain/input.rs +++ b/zkstack_cli/crates/config/src/forge_interface/register_chain/input.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use types::L1BatchCommitmentMode; use zksync_basic_types::L2ChainId; -use crate::{traits::ZkToolboxConfig, ChainConfig, ContractsConfig}; +use crate::{traits::ZkStackConfig, ChainConfig, ContractsConfig}; #[derive(Debug, Deserialize, Serialize, Clone)] struct Bridgehub { @@ -50,7 +50,7 @@ pub struct ChainL1Config { pub governance_min_delay: u64, } -impl ZkToolboxConfig for RegisterChainL1Config {} +impl ZkStackConfig for RegisterChainL1Config {} impl RegisterChainL1Config { pub fn new(chain_config: &ChainConfig, contracts: &ContractsConfig) -> anyhow::Result { diff --git a/zk_toolbox/crates/config/src/forge_interface/register_chain/mod.rs b/zkstack_cli/crates/config/src/forge_interface/register_chain/mod.rs similarity index 100% rename from zk_toolbox/crates/config/src/forge_interface/register_chain/mod.rs rename to zkstack_cli/crates/config/src/forge_interface/register_chain/mod.rs diff --git a/zk_toolbox/crates/config/src/forge_interface/register_chain/output.rs b/zkstack_cli/crates/config/src/forge_interface/register_chain/output.rs similarity index 75% rename from zk_toolbox/crates/config/src/forge_interface/register_chain/output.rs rename to zkstack_cli/crates/config/src/forge_interface/register_chain/output.rs index f9521b16328f..a3e23f7bae42 100644 --- a/zk_toolbox/crates/config/src/forge_interface/register_chain/output.rs +++ b/zkstack_cli/crates/config/src/forge_interface/register_chain/output.rs @@ -1,7 +1,7 @@ use ethers::types::Address; use serde::{Deserialize, Serialize}; -use crate::traits::ZkToolboxConfig; +use crate::traits::ZkStackConfig; #[derive(Debug, Deserialize, Serialize, Clone)] pub struct RegisterChainOutput { @@ -10,4 +10,4 @@ pub struct RegisterChainOutput { pub chain_admin_addr: Address, } -impl ZkToolboxConfig for RegisterChainOutput {} +impl ZkStackConfig for RegisterChainOutput {} diff --git a/zk_toolbox/crates/config/src/forge_interface/script_params.rs b/zkstack_cli/crates/config/src/forge_interface/script_params.rs similarity index 100% rename from zk_toolbox/crates/config/src/forge_interface/script_params.rs rename to zkstack_cli/crates/config/src/forge_interface/script_params.rs diff --git a/zk_toolbox/crates/config/src/forge_interface/setup_legacy_bridge/mod.rs b/zkstack_cli/crates/config/src/forge_interface/setup_legacy_bridge/mod.rs similarity index 86% rename from zk_toolbox/crates/config/src/forge_interface/setup_legacy_bridge/mod.rs rename to zkstack_cli/crates/config/src/forge_interface/setup_legacy_bridge/mod.rs index e8189c521fb3..201cf86b734b 100644 --- a/zk_toolbox/crates/config/src/forge_interface/setup_legacy_bridge/mod.rs +++ b/zkstack_cli/crates/config/src/forge_interface/setup_legacy_bridge/mod.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use zksync_basic_types::{Address, L2ChainId, H256}; -use crate::traits::ZkToolboxConfig; +use crate::traits::ZkStackConfig; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SetupLegacyBridgeInput { @@ -17,4 +17,4 @@ pub struct SetupLegacyBridgeInput { pub create2factory_addr: Address, } -impl ZkToolboxConfig for SetupLegacyBridgeInput {} +impl ZkStackConfig for SetupLegacyBridgeInput {} diff --git a/zk_toolbox/crates/config/src/general.rs b/zkstack_cli/crates/config/src/general.rs similarity index 100% rename from zk_toolbox/crates/config/src/general.rs rename to zkstack_cli/crates/config/src/general.rs diff --git a/zk_toolbox/crates/config/src/genesis.rs b/zkstack_cli/crates/config/src/genesis.rs similarity index 100% rename from zk_toolbox/crates/config/src/genesis.rs rename to zkstack_cli/crates/config/src/genesis.rs diff --git a/zk_toolbox/crates/config/src/lib.rs b/zkstack_cli/crates/config/src/lib.rs similarity index 100% rename from zk_toolbox/crates/config/src/lib.rs rename to zkstack_cli/crates/config/src/lib.rs diff --git a/zk_toolbox/crates/config/src/manipulations.rs b/zkstack_cli/crates/config/src/manipulations.rs similarity index 100% rename from zk_toolbox/crates/config/src/manipulations.rs rename to zkstack_cli/crates/config/src/manipulations.rs diff --git a/zk_toolbox/crates/config/src/portal.rs b/zkstack_cli/crates/config/src/portal.rs similarity index 98% rename from zk_toolbox/crates/config/src/portal.rs rename to zkstack_cli/crates/config/src/portal.rs index c787c6cc7026..2b6f0ffd5156 100644 --- a/zk_toolbox/crates/config/src/portal.rs +++ b/zkstack_cli/crates/config/src/portal.rs @@ -9,7 +9,7 @@ use crate::{ LOCAL_APPS_PATH, LOCAL_CONFIGS_PATH, LOCAL_GENERATED_PATH, PORTAL_CONFIG_FILE, PORTAL_JS_CONFIG_FILE, }, - traits::{ReadConfig, SaveConfig, ZkToolboxConfig}, + traits::{ReadConfig, SaveConfig, ZkStackConfig}, }; /// Portal JSON configuration file. This file contains configuration for the portal app. @@ -172,4 +172,4 @@ impl Default for PortalConfig { } } -impl ZkToolboxConfig for PortalConfig {} +impl ZkStackConfig for PortalConfig {} diff --git a/zk_toolbox/crates/config/src/secrets.rs b/zkstack_cli/crates/config/src/secrets.rs similarity index 100% rename from zk_toolbox/crates/config/src/secrets.rs rename to zkstack_cli/crates/config/src/secrets.rs diff --git a/zk_toolbox/crates/config/src/traits.rs b/zkstack_cli/crates/config/src/traits.rs similarity index 95% rename from zk_toolbox/crates/config/src/traits.rs rename to zkstack_cli/crates/config/src/traits.rs index bb0722762e31..a4a4ad22c613 100644 --- a/zk_toolbox/crates/config/src/traits.rs +++ b/zkstack_cli/crates/config/src/traits.rs @@ -8,8 +8,8 @@ use serde::{de::DeserializeOwned, Serialize}; use url::Url; use xshell::Shell; -// Configs that we use only inside zk toolbox, we don't have protobuf implementation for them. -pub trait ZkToolboxConfig {} +// Configs that we use only inside ZK Stack CLI, we don't have protobuf implementation for them. +pub trait ZkStackConfig {} pub trait FileConfigWithDefaultName { const FILE_NAME: &'static str; @@ -19,7 +19,7 @@ pub trait FileConfigWithDefaultName { } } -impl SaveConfig for T { +impl SaveConfig for T { fn save(&self, shell: &Shell, path: impl AsRef) -> anyhow::Result<()> { save_with_comment(shell, path, self, "") } @@ -49,7 +49,7 @@ pub trait ReadConfig: Sized { impl ReadConfig for T where - T: DeserializeOwned + Clone + ZkToolboxConfig, + T: DeserializeOwned + Clone + ZkStackConfig, { fn read(shell: &Shell, path: impl AsRef) -> anyhow::Result { let error_context = || format!("Failed to parse config file {:?}.", path.as_ref()); diff --git a/zk_toolbox/crates/config/src/wallet_creation.rs b/zkstack_cli/crates/config/src/wallet_creation.rs similarity index 100% rename from zk_toolbox/crates/config/src/wallet_creation.rs rename to zkstack_cli/crates/config/src/wallet_creation.rs diff --git a/zk_toolbox/crates/config/src/wallets.rs b/zkstack_cli/crates/config/src/wallets.rs similarity index 91% rename from zk_toolbox/crates/config/src/wallets.rs rename to zkstack_cli/crates/config/src/wallets.rs index c650781bff53..735848f6e34d 100644 --- a/zk_toolbox/crates/config/src/wallets.rs +++ b/zkstack_cli/crates/config/src/wallets.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{ consts::WALLETS_FILE, - traits::{FileConfigWithDefaultName, ZkToolboxConfig}, + traits::{FileConfigWithDefaultName, ZkStackConfig}, }; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -55,6 +55,6 @@ pub(crate) struct EthMnemonicConfig { pub(crate) base_path: String, } -impl ZkToolboxConfig for EthMnemonicConfig {} +impl ZkStackConfig for EthMnemonicConfig {} -impl ZkToolboxConfig for WalletsConfig {} +impl ZkStackConfig for WalletsConfig {} diff --git a/zk_toolbox/crates/git_version_macro/Cargo.toml b/zkstack_cli/crates/git_version_macro/Cargo.toml similarity index 100% rename from zk_toolbox/crates/git_version_macro/Cargo.toml rename to zkstack_cli/crates/git_version_macro/Cargo.toml diff --git a/zk_toolbox/crates/git_version_macro/src/lib.rs b/zkstack_cli/crates/git_version_macro/src/lib.rs similarity index 100% rename from zk_toolbox/crates/git_version_macro/src/lib.rs rename to zkstack_cli/crates/git_version_macro/src/lib.rs diff --git a/zk_toolbox/crates/types/Cargo.toml b/zkstack_cli/crates/types/Cargo.toml similarity index 100% rename from zk_toolbox/crates/types/Cargo.toml rename to zkstack_cli/crates/types/Cargo.toml diff --git a/zk_toolbox/crates/types/src/base_token.rs b/zkstack_cli/crates/types/src/base_token.rs similarity index 100% rename from zk_toolbox/crates/types/src/base_token.rs rename to zkstack_cli/crates/types/src/base_token.rs diff --git a/zk_toolbox/crates/types/src/l1_network.rs b/zkstack_cli/crates/types/src/l1_network.rs similarity index 100% rename from zk_toolbox/crates/types/src/l1_network.rs rename to zkstack_cli/crates/types/src/l1_network.rs diff --git a/zk_toolbox/crates/types/src/lib.rs b/zkstack_cli/crates/types/src/lib.rs similarity index 100% rename from zk_toolbox/crates/types/src/lib.rs rename to zkstack_cli/crates/types/src/lib.rs diff --git a/zk_toolbox/crates/types/src/prover_mode.rs b/zkstack_cli/crates/types/src/prover_mode.rs similarity index 100% rename from zk_toolbox/crates/types/src/prover_mode.rs rename to zkstack_cli/crates/types/src/prover_mode.rs diff --git a/zk_toolbox/crates/types/src/token_info.rs b/zkstack_cli/crates/types/src/token_info.rs similarity index 100% rename from zk_toolbox/crates/types/src/token_info.rs rename to zkstack_cli/crates/types/src/token_info.rs diff --git a/zk_toolbox/crates/types/src/wallet_creation.rs b/zkstack_cli/crates/types/src/wallet_creation.rs similarity index 100% rename from zk_toolbox/crates/types/src/wallet_creation.rs rename to zkstack_cli/crates/types/src/wallet_creation.rs diff --git a/zk_toolbox/crates/zk_inception/Cargo.toml b/zkstack_cli/crates/zkstack/Cargo.toml similarity index 93% rename from zk_toolbox/crates/zk_inception/Cargo.toml rename to zkstack_cli/crates/zkstack/Cargo.toml index e6687bdd9815..a9fcecaf79b4 100644 --- a/zk_toolbox/crates/zk_inception/Cargo.toml +++ b/zkstack_cli/crates/zkstack/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "zk_inception" +name = "zkstack" version = "0.1.0" edition.workspace = true homepage.workspace = true @@ -12,33 +12,36 @@ keywords.workspace = true [dependencies] anyhow.workspace = true +chrono.workspace = true clap.workspace = true +clap-markdown.workspace = true cliclack.workspace = true +common.workspace = true config.workspace = true +ethers.workspace = true +futures.workspace = true human-panic.workspace = true lazy_static.workspace = true -serde_yaml.workspace = true +secrecy.workspace = true serde.workspace = true serde_json.workspace = true -xshell.workspace = true -ethers.workspace = true -common.workspace = true -tokio.workspace = true -types.workspace = true +serde_yaml.workspace = true +slugify-rs.workspace = true strum.workspace = true +sqruff-lib = "0.19.0" +thiserror.workspace = true +tokio.workspace = true toml.workspace = true +types.workspace = true url.workspace = true -thiserror.workspace = true -zksync_config.workspace = true -slugify-rs.workspace = true +xshell.workspace = true zksync_basic_types.workspace = true -clap-markdown.workspace = true +zksync_config.workspace = true zksync_consensus_roles.workspace = true zksync_consensus_crypto.workspace = true zksync_protobuf.workspace = true zksync_protobuf_config.workspace = true prost.workspace = true -secrecy.workspace = true reqwest = "0.12.8" [dev-dependencies] diff --git a/zk_toolbox/crates/zk_inception/README.md b/zkstack_cli/crates/zkstack/README.md similarity index 99% rename from zk_toolbox/crates/zk_inception/README.md rename to zkstack_cli/crates/zkstack/README.md index 7fbbb58c88f3..6e529efc2009 100644 --- a/zk_toolbox/crates/zk_inception/README.md +++ b/zkstack_cli/crates/zkstack/README.md @@ -42,7 +42,7 @@ This document contains the help content for the `zk_inception` command-line prog ## `zk_inception` -ZK Toolbox is a set of tools for working with zk stack. +ZK Stack CLI is a set of tools for working with zk stack. **Usage:** `zk_inception [OPTIONS] ` diff --git a/zk_toolbox/crates/zk_inception/abi/ConsensusRegistry.json b/zkstack_cli/crates/zkstack/abi/ConsensusRegistry.json similarity index 100% rename from zk_toolbox/crates/zk_inception/abi/ConsensusRegistry.json rename to zkstack_cli/crates/zkstack/abi/ConsensusRegistry.json diff --git a/zk_toolbox/crates/zk_inception/build.rs b/zkstack_cli/crates/zkstack/build.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/build.rs rename to zkstack_cli/crates/zkstack/build.rs diff --git a/zk_toolbox/crates/zk_inception/src/accept_ownership.rs b/zkstack_cli/crates/zkstack/src/accept_ownership.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/accept_ownership.rs rename to zkstack_cli/crates/zkstack/src/accept_ownership.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/args/containers.rs b/zkstack_cli/crates/zkstack/src/commands/args/containers.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/args/containers.rs rename to zkstack_cli/crates/zkstack/src/commands/args/containers.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/args/mod.rs b/zkstack_cli/crates/zkstack/src/commands/args/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/args/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/args/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/args/run_server.rs b/zkstack_cli/crates/zkstack/src/commands/args/run_server.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/args/run_server.rs rename to zkstack_cli/crates/zkstack/src/commands/args/run_server.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/args/update.rs b/zkstack_cli/crates/zkstack/src/commands/args/update.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/args/update.rs rename to zkstack_cli/crates/zkstack/src/commands/args/update.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/accept_chain_ownership.rs b/zkstack_cli/crates/zkstack/src/commands/chain/accept_chain_ownership.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/accept_chain_ownership.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/accept_chain_ownership.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build_transactions.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/build_transactions.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/args/build_transactions.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/args/build_transactions.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/genesis.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/genesis.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/args/genesis.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/args/genesis.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/init/configs.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/args/init/configs.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/init/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/args/init/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/args/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs b/zkstack_cli/crates/zkstack/src/commands/chain/build_transactions.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/build_transactions.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/common.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/common.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/create.rs b/zkstack_cli/crates/zkstack/src/commands/chain/create.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/create.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/create.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs b/zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/deploy_l2_contracts.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs b/zkstack_cli/crates/zkstack/src/commands/chain/deploy_paymaster.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/deploy_paymaster.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/genesis/database.rs b/zkstack_cli/crates/zkstack/src/commands/chain/genesis/database.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/genesis/database.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/genesis/database.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/genesis/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/genesis/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/genesis/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/genesis/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/genesis/server.rs b/zkstack_cli/crates/zkstack/src/commands/chain/genesis/server.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/genesis/server.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/genesis/server.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init/configs.rs b/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs similarity index 79% rename from zk_toolbox/crates/zk_inception/src/commands/chain/init/configs.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs index d0897473b832..37ee2e076ab9 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs @@ -2,7 +2,7 @@ use anyhow::Context; use common::logger; use config::{ copy_configs, set_l1_rpc_url, traits::SaveConfigWithBasePath, update_from_chain_config, - ChainConfig, ContractsConfig, EcosystemConfig, DEFAULT_CONSENSUS_PORT, + ChainConfig, ContractsConfig, EcosystemConfig, }; use ethers::types::Address; use xshell::Shell; @@ -15,13 +15,12 @@ use crate::{ }, portal::update_portal_config, }, - defaults::PORT_RANGE_END, messages::{ - MSG_CHAIN_CONFIGS_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, + MSG_CHAIN_CONFIGS_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, MSG_CONSENSUS_CONFIG_MISSING_ERR, MSG_PORTAL_FAILED_TO_CREATE_CONFIG_ERR, }, utils::{ - consensus::{generate_consensus_keys, get_consensus_config, get_consensus_secrets}, + consensus::{generate_consensus_keys, get_consensus_secrets, get_genesis_specs}, ports::EcosystemPortsScanner, }, }; @@ -57,22 +56,14 @@ pub async fn init_configs( )?; } - // Initialize general config let mut general_config = chain_config.get_general_config()?; - - // TODO: This is a temporary solution. We should allocate consensus port using `EcosystemPorts::allocate_ports_in_yaml` - let offset = ((chain_config.id - 1) * 100) as u16; - let consensus_port_range = DEFAULT_CONSENSUS_PORT + offset..PORT_RANGE_END; - let consensus_port = - ecosystem_ports.allocate_port(consensus_port_range, "Consensus".to_string())?; + let mut consensus_config = general_config + .consensus_config + .context(MSG_CONSENSUS_CONFIG_MISSING_ERR)?; let consensus_keys = generate_consensus_keys(); - let consensus_config = get_consensus_config( - chain_config, - consensus_port, - Some(consensus_keys.clone()), - None, - )?; + consensus_config.genesis_spec = Some(get_genesis_specs(chain_config, &consensus_keys)); + general_config.consensus_config = Some(consensus_config); general_config.save_with_base_path(shell, &chain_config.configs)?; diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/init/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/register_chain.rs b/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/register_chain.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/set_token_multiplier_setter.rs b/zkstack_cli/crates/zkstack/src/commands/chain/set_token_multiplier_setter.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/set_token_multiplier_setter.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/set_token_multiplier_setter.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/setup_legacy_bridge.rs b/zkstack_cli/crates/zkstack/src/commands/chain/setup_legacy_bridge.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/chain/setup_legacy_bridge.rs rename to zkstack_cli/crates/zkstack/src/commands/chain/setup_legacy_bridge.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/consensus/conv.rs b/zkstack_cli/crates/zkstack/src/commands/consensus/conv.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/consensus/conv.rs rename to zkstack_cli/crates/zkstack/src/commands/consensus/conv.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/consensus/mod.rs b/zkstack_cli/crates/zkstack/src/commands/consensus/mod.rs similarity index 92% rename from zk_toolbox/crates/zk_inception/src/commands/consensus/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/consensus/mod.rs index a21ba2d62cf9..1855a5943dc7 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/consensus/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/consensus/mod.rs @@ -3,7 +3,7 @@ use std::{borrow::Borrow, collections::HashMap, path::PathBuf, sync::Arc}; /// Consensus registry contract operations. /// Includes code duplicated from `zksync_node_consensus::registry::abi`. use anyhow::Context as _; -use common::logger; +use common::{logger, wallets::Wallet}; use config::EcosystemConfig; use conv::*; use ethers::{ @@ -11,7 +11,7 @@ use ethers::{ contract::{FunctionCall, Multicall}, middleware::{Middleware, NonceManagerMiddleware, SignerMiddleware}, providers::{Http, JsonRpcClient, PendingTransaction, Provider, RawCall as _}, - signers::Signer as _, + signers::{LocalWallet, Signer as _}, types::{Address, BlockId, H256}, }; use xshell::Shell; @@ -174,19 +174,20 @@ impl Setup { )?) } - fn governor(&self) -> anyhow::Result> { - let governor = self + fn governor(&self) -> anyhow::Result { + Ok(self .chain .get_wallets_config() .context("get_wallets_config()")? - .governor - .private_key - .context(messages::MSG_GOVERNOR_PRIVATE_KEY_NOT_SET)?; - let governor = governor.with_chain_id(self.genesis.l2_chain_id.as_u64()); + .governor) + } + + fn signer(&self, wallet: LocalWallet) -> anyhow::Result> { + let wallet = wallet.with_chain_id(self.genesis.l2_chain_id.as_u64()); let provider = self.provider().context("provider()")?; - let signer = SignerMiddleware::new(provider, governor.clone()); + let signer = SignerMiddleware::new(provider, wallet.clone()); // Allows us to send next transaction without waiting for the previous to complete. - let signer = NonceManagerMiddleware::new(signer, governor.address()); + let signer = NonceManagerMiddleware::new(signer, wallet.address()); Ok(Arc::new(signer)) } @@ -279,10 +280,25 @@ impl Setup { let provider = self.provider().context("provider()")?; let block_id = self.last_block(&provider).await.context("last_block()")?; let governor = self.governor().context("governor()")?; + let signer = self.signer( + governor + .private_key + .clone() + .context(messages::MSG_GOVERNOR_PRIVATE_KEY_NOT_SET)?, + )?; let consensus_registry = self - .consensus_registry(governor.clone()) + .consensus_registry(signer.clone()) .context("consensus_registry()")?; - let mut multicall = self.multicall(governor.clone()).context("multicall()")?; + let mut multicall = self.multicall(signer).context("multicall()")?; + + let owner = consensus_registry.owner().call().await.context("owner()")?; + if owner != governor.address { + anyhow::bail!( + "governor ({:#x}) is different than the consensus registry owner ({:#x})", + governor.address, + owner + ); + } // Fetch contract state. let n: usize = consensus_registry diff --git a/zk_toolbox/crates/zk_inception/src/commands/consensus/proto/mod.proto b/zkstack_cli/crates/zkstack/src/commands/consensus/proto/mod.proto similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/consensus/proto/mod.proto rename to zkstack_cli/crates/zkstack/src/commands/consensus/proto/mod.proto diff --git a/zk_toolbox/crates/zk_inception/src/commands/consensus/proto/mod.rs b/zkstack_cli/crates/zkstack/src/commands/consensus/proto/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/consensus/proto/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/consensus/proto/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/consensus/tests.rs b/zkstack_cli/crates/zkstack/src/commands/consensus/tests.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/consensus/tests.rs rename to zkstack_cli/crates/zkstack/src/commands/consensus/tests.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/containers.rs b/zkstack_cli/crates/zkstack/src/commands/containers.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/containers.rs rename to zkstack_cli/crates/zkstack/src/commands/containers.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/contract_verifier/args/init.rs b/zkstack_cli/crates/zkstack/src/commands/contract_verifier/args/init.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/contract_verifier/args/init.rs rename to zkstack_cli/crates/zkstack/src/commands/contract_verifier/args/init.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/contract_verifier/args/mod.rs b/zkstack_cli/crates/zkstack/src/commands/contract_verifier/args/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/contract_verifier/args/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/contract_verifier/args/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/contract_verifier/args/releases.rs b/zkstack_cli/crates/zkstack/src/commands/contract_verifier/args/releases.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/contract_verifier/args/releases.rs rename to zkstack_cli/crates/zkstack/src/commands/contract_verifier/args/releases.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/contract_verifier/init.rs b/zkstack_cli/crates/zkstack/src/commands/contract_verifier/init.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/contract_verifier/init.rs rename to zkstack_cli/crates/zkstack/src/commands/contract_verifier/init.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/contract_verifier/mod.rs b/zkstack_cli/crates/zkstack/src/commands/contract_verifier/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/contract_verifier/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/contract_verifier/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/contract_verifier/run.rs b/zkstack_cli/crates/zkstack/src/commands/contract_verifier/run.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/contract_verifier/run.rs rename to zkstack_cli/crates/zkstack/src/commands/contract_verifier/run.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/clean/mod.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/clean/mod.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/clean/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/clean/mod.rs index 803e962c0ff8..4cb419ce7a46 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/clean/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/clean/mod.rs @@ -4,7 +4,7 @@ use common::{docker, logger}; use config::{EcosystemConfig, DOCKER_COMPOSE_FILE}; use xshell::Shell; -use crate::messages::{ +use crate::commands::dev::messages::{ MSG_CONTRACTS_CLEANING, MSG_CONTRACTS_CLEANING_FINISHED, MSG_DOCKER_COMPOSE_CLEANED, MSG_DOCKER_COMPOSE_DOWN, MSG_DOCKER_COMPOSE_REMOVE_VOLUMES, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/config_writer.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/config_writer.rs similarity index 96% rename from zk_toolbox/crates/zk_supervisor/src/commands/config_writer.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/config_writer.rs index 04e019936e17..70238ed15f32 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/config_writer.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/config_writer.rs @@ -4,7 +4,7 @@ use common::{logger, Prompt}; use config::{override_config, EcosystemConfig}; use xshell::Shell; -use crate::messages::{ +use crate::commands::dev::messages::{ msg_overriding_config, MSG_CHAIN_NOT_FOUND_ERR, MSG_OVERRIDE_CONFIG_PATH_HELP, MSG_OVERRIDE_SUCCESS, MSG_OVERRRIDE_CONFIG_PATH_PROMPT, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/contracts.rs similarity index 99% rename from zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/contracts.rs index 4bb1638be693..fbafaec09e6e 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/contracts.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/contracts.rs @@ -11,7 +11,7 @@ use common::{ use config::EcosystemConfig; use xshell::Shell; -use crate::messages::{ +use crate::commands::dev::messages::{ MSG_BUILDING_CONTRACTS, MSG_BUILDING_CONTRACTS_SUCCESS, MSG_BUILDING_L1_CONTRACTS_SPINNER, MSG_BUILDING_L2_CONTRACTS_SPINNER, MSG_BUILDING_SYSTEM_CONTRACTS_SPINNER, MSG_BUILDING_TEST_CONTRACTS_SPINNER, MSG_BUILD_L1_CONTRACTS_HELP, MSG_BUILD_L2_CONTRACTS_HELP, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/mod.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/args/mod.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/database/args/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/database/args/mod.rs index cf9dfc2834a8..f05e3ee1c0e0 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/args/mod.rs @@ -1,6 +1,6 @@ use clap::Parser; -use crate::{ +use crate::commands::dev::{ dals::SelectedDals, messages::{ MSG_DATABASE_COMMON_CORE_HELP, MSG_DATABASE_COMMON_CORE_URL_HELP, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/new_migration.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/args/new_migration.rs similarity index 97% rename from zk_toolbox/crates/zk_supervisor/src/commands/database/args/new_migration.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/database/args/new_migration.rs index 64b7a507abea..b91b048be784 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/new_migration.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/args/new_migration.rs @@ -2,7 +2,7 @@ use clap::{Parser, ValueEnum}; use common::{Prompt, PromptSelect}; use strum::{Display, EnumIter, IntoEnumIterator}; -use crate::messages::{ +use crate::commands::dev::messages::{ MSG_DATABASE_NEW_MIGRATION_DATABASE_HELP, MSG_DATABASE_NEW_MIGRATION_DB_PROMPT, MSG_DATABASE_NEW_MIGRATION_NAME_HELP, MSG_DATABASE_NEW_MIGRATION_NAME_PROMPT, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/check_sqlx_data.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/check_sqlx_data.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/database/check_sqlx_data.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/database/check_sqlx_data.rs index 0c401595690e..990fca78641f 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/check_sqlx_data.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/check_sqlx_data.rs @@ -5,7 +5,7 @@ use config::EcosystemConfig; use xshell::{cmd, Shell}; use super::args::DatabaseCommonArgs; -use crate::{ +use crate::commands::dev::{ dals::{get_dals, Dal}, messages::{ msg_database_info, msg_database_loading, msg_database_success, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/drop.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/drop.rs similarity index 97% rename from zk_toolbox/crates/zk_supervisor/src/commands/database/drop.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/database/drop.rs index 94bf325a2c6c..a5578d41f77a 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/drop.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/drop.rs @@ -6,7 +6,7 @@ use common::{ use xshell::Shell; use super::args::DatabaseCommonArgs; -use crate::{ +use crate::commands::dev::{ dals::{get_dals, Dal}, messages::{ msg_database_info, msg_database_loading, msg_database_success, MSG_DATABASE_DROP_GERUND, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/migrate.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/migrate.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/database/migrate.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/database/migrate.rs index 1d648965c244..fd22f769742e 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/migrate.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/migrate.rs @@ -5,7 +5,7 @@ use config::EcosystemConfig; use xshell::{cmd, Shell}; use super::args::DatabaseCommonArgs; -use crate::{ +use crate::commands::dev::{ dals::{get_dals, Dal}, messages::{ msg_database_info, msg_database_loading, msg_database_success, MSG_DATABASE_MIGRATE_GERUND, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/mod.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/mod.rs similarity index 97% rename from zk_toolbox/crates/zk_supervisor/src/commands/database/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/database/mod.rs index 415b81879f1b..ed039fc65019 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/mod.rs @@ -2,7 +2,7 @@ use clap::Subcommand; use xshell::Shell; use self::args::{new_migration::DatabaseNewMigrationArgs, DatabaseCommonArgs}; -use crate::messages::{ +use crate::commands::dev::messages::{ MSG_DATABASE_CHECK_SQLX_DATA_ABOUT, MSG_DATABASE_DROP_ABOUT, MSG_DATABASE_MIGRATE_ABOUT, MSG_DATABASE_NEW_MIGRATION_ABOUT, MSG_DATABASE_PREPARE_ABOUT, MSG_DATABASE_RESET_ABOUT, MSG_DATABASE_SETUP_ABOUT, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/new_migration.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/new_migration.rs similarity index 97% rename from zk_toolbox/crates/zk_supervisor/src/commands/database/new_migration.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/database/new_migration.rs index e21b7cde47ba..2d9fa1030538 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/new_migration.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/new_migration.rs @@ -5,7 +5,7 @@ use config::EcosystemConfig; use xshell::{cmd, Shell}; use super::args::new_migration::{DatabaseNewMigrationArgs, SelectedDatabase}; -use crate::{ +use crate::commands::dev::{ dals::{get_core_dal, get_prover_dal, Dal}, messages::{msg_database_new_migration_loading, MSG_DATABASE_NEW_MIGRATION_SUCCESS}, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/prepare.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/prepare.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/database/prepare.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/database/prepare.rs index 82ec12f94129..288a68452fd5 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/prepare.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/prepare.rs @@ -5,7 +5,7 @@ use config::EcosystemConfig; use xshell::{cmd, Shell}; use super::args::DatabaseCommonArgs; -use crate::{ +use crate::commands::dev::{ dals::{get_dals, Dal}, messages::{ msg_database_info, msg_database_loading, msg_database_success, MSG_DATABASE_PREPARE_GERUND, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/reset.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/reset.rs similarity index 97% rename from zk_toolbox/crates/zk_supervisor/src/commands/database/reset.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/database/reset.rs index f0262cecb959..55d5ab1cbfcb 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/reset.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/reset.rs @@ -5,7 +5,7 @@ use config::EcosystemConfig; use xshell::Shell; use super::{args::DatabaseCommonArgs, drop::drop_database, setup::setup_database}; -use crate::{ +use crate::commands::dev::{ dals::{get_dals, Dal}, messages::{ msg_database_info, msg_database_loading, msg_database_success, MSG_DATABASE_RESET_GERUND, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/setup.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/setup.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/database/setup.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/database/setup.rs index 15b3ac5c1c72..74ade66ba481 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/setup.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/database/setup.rs @@ -5,7 +5,7 @@ use config::EcosystemConfig; use xshell::{cmd, Shell}; use super::args::DatabaseCommonArgs; -use crate::{ +use crate::commands::dev::{ dals::{get_dals, Dal}, messages::{ msg_database_info, msg_database_loading, msg_database_success, MSG_DATABASE_SETUP_GERUND, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/fmt.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/fmt.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/fmt.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/fmt.rs index a6db4643c30a..ebaf27845e0a 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/fmt.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/fmt.rs @@ -6,7 +6,7 @@ use config::EcosystemConfig; use xshell::{cmd, Shell}; use super::sql_fmt::format_sql; -use crate::{ +use crate::commands::dev::{ commands::lint_utils::{get_unignored_files, Target}, messages::{ msg_running_fmt_for_extension_spinner, msg_running_fmt_for_extensions_spinner, @@ -42,7 +42,7 @@ async fn prettier_contracts(shell: Shell, check: bool) -> anyhow::Result<()> { } async fn rustfmt(shell: Shell, check: bool, link_to_code: PathBuf) -> anyhow::Result<()> { - for dir in [".", "prover", "zk_toolbox"] { + for dir in [".", "prover", "zkstack_cli"] { let spinner = Spinner::new(&msg_running_rustfmt_for_dir_spinner(dir)); let _dir = shell.push_dir(link_to_code.join(dir)); let mut cmd = cmd!(shell, "cargo fmt -- --config imports_granularity=Crate --config group_imports=StdExternalCrate"); diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/genesis.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/genesis.rs similarity index 80% rename from zk_toolbox/crates/zk_supervisor/src/commands/genesis.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/genesis.rs index 47d2f0075ae6..683ffe199161 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/genesis.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/genesis.rs @@ -4,9 +4,11 @@ use config::EcosystemConfig; use xshell::{cmd, Shell}; use crate::{ - commands::database::reset::reset_database, - dals::get_core_dal, - messages::{MSG_CHAIN_NOT_FOUND_ERR, MSG_GENESIS_FILE_GENERATION_STARTED}, + commands::dev::{ + commands::database::reset::reset_database, dals::get_core_dal, + messages::MSG_GENESIS_FILE_GENERATION_STARTED, + }, + messages::MSG_CHAIN_NOT_FOUND_ERR, }; pub(crate) async fn run(shell: &Shell) -> anyhow::Result<()> { diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/lint.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs similarity index 95% rename from zk_toolbox/crates/zk_supervisor/src/commands/lint.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs index 45a7a46ebbe0..71f21a02e739 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/lint.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint.rs @@ -3,7 +3,7 @@ use common::{cmd::Cmd, logger, spinner::Spinner}; use config::EcosystemConfig; use xshell::{cmd, Shell}; -use crate::{ +use crate::commands::dev::{ commands::lint_utils::{get_unignored_files, Target}, messages::{ msg_running_linter_for_extension_spinner, msg_running_linters_for_files, @@ -55,8 +55,8 @@ fn lint_rs(shell: &Shell, ecosystem: &EcosystemConfig, check: bool) -> anyhow::R let link_to_code = &ecosystem.link_to_code; let lint_to_prover = &ecosystem.link_to_code.join("prover"); - let link_to_toolbox = &ecosystem.link_to_code.join("zk_toolbox"); - let paths = vec![link_to_code, lint_to_prover, link_to_toolbox]; + let link_to_zkstack = &ecosystem.link_to_code.join("zkstack_cli"); + let paths = vec![link_to_code, lint_to_prover, link_to_zkstack]; spinner.freeze(); for path in paths { diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/lint_utils.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/lint_utils.rs similarity index 100% rename from zk_toolbox/crates/zk_supervisor/src/commands/lint_utils.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/lint_utils.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_supervisor/src/commands/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/mod.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/prover/args/insert_batch.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/args/insert_batch.rs similarity index 100% rename from zk_toolbox/crates/zk_supervisor/src/commands/prover/args/insert_batch.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/args/insert_batch.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/prover/args/insert_version.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/args/insert_version.rs similarity index 100% rename from zk_toolbox/crates/zk_supervisor/src/commands/prover/args/insert_version.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/args/insert_version.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/prover/args/mod.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/args/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_supervisor/src/commands/prover/args/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/args/mod.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/prover/info.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/info.rs similarity index 97% rename from zk_toolbox/crates/zk_supervisor/src/commands/prover/info.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/info.rs index 441edb2c4b2d..84873e931b3e 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/prover/info.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/info.rs @@ -8,7 +8,7 @@ use common::logger; use config::{ChainConfig, EcosystemConfig}; use xshell::{cmd, Shell}; -use crate::messages::MSG_CHAIN_NOT_FOUND_ERR; +use crate::commands::dev::messages::MSG_CHAIN_NOT_FOUND_ERR; pub async fn run(shell: &Shell) -> anyhow::Result<()> { let ecosystem_config = EcosystemConfig::from_file(shell)?; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/prover/insert_batch.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/insert_batch.rs similarity index 97% rename from zk_toolbox/crates/zk_supervisor/src/commands/prover/insert_batch.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/insert_batch.rs index 8c2cdd4d88dd..0e0c0ba33af4 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/prover/insert_batch.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/insert_batch.rs @@ -2,7 +2,7 @@ use common::{check_prerequisites, cmd::Cmd, logger, PROVER_CLI_PREREQUISITE}; use config::{get_link_to_prover, EcosystemConfig}; use xshell::{cmd, Shell}; -use crate::{ +use crate::commands::dev::{ commands::prover::{ args::insert_batch::{InsertBatchArgs, InsertBatchArgsFinal}, info, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/prover/insert_version.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/insert_version.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/prover/insert_version.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/insert_version.rs index 3dd9b7e0a1b1..f7bd175f577a 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/prover/insert_version.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/insert_version.rs @@ -2,7 +2,7 @@ use common::{check_prerequisites, cmd::Cmd, logger, PROVER_CLI_PREREQUISITE}; use config::{get_link_to_prover, EcosystemConfig}; use xshell::{cmd, Shell}; -use crate::{ +use crate::commands::dev::{ commands::prover::{ args::insert_version::{InsertVersionArgs, InsertVersionArgsFinal}, info, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/prover/mod.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_supervisor/src/commands/prover/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/prover/mod.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/send_transactions/args/mod.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/send_transactions/args/mod.rs index e3d4f220ff28..03d9ec9b7360 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/send_transactions/args/mod.rs @@ -4,7 +4,7 @@ use clap::Parser; use common::Prompt; use url::Url; -use crate::{ +use crate::commands::dev::{ defaults::LOCAL_RPC_URL, messages::{ MSG_INVALID_L1_RPC_URL_ERR, MSG_PROMPT_L1_RPC_URL, MSG_PROMPT_SECRET_KEY, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/send_transactions/mod.rs similarity index 99% rename from zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/send_transactions/mod.rs index 79d8efc600e8..2f54579ade9e 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/send_transactions/mod.rs @@ -17,7 +17,7 @@ use tokio::time::sleep; use xshell::Shell; use zksync_basic_types::{H160, U256}; -use crate::{ +use crate::commands::dev::{ consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR, messages::{ msg_send_txns_outro, MSG_FAILED_TO_SEND_TXN_ERR, MSG_UNABLE_TO_OPEN_FILE_ERR, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/snapshot.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/snapshot.rs similarity index 91% rename from zk_toolbox/crates/zk_supervisor/src/commands/snapshot.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/snapshot.rs index 608c56233348..8e4c7183cb55 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/snapshot.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/snapshot.rs @@ -4,7 +4,7 @@ use common::{cmd::Cmd, logger}; use config::EcosystemConfig; use xshell::{cmd, Shell}; -use crate::messages::{MSG_CHAIN_NOT_FOUND_ERR, MSG_RUNNING_SNAPSHOT_CREATOR}; +use crate::commands::dev::messages::{MSG_CHAIN_NOT_FOUND_ERR, MSG_RUNNING_SNAPSHOT_CREATOR}; #[derive(Subcommand, Debug)] pub enum SnapshotCommands { diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/sql_fmt.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/sql_fmt.rs similarity index 97% rename from zk_toolbox/crates/zk_supervisor/src/commands/sql_fmt.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/sql_fmt.rs index ede2500e6ab6..0f7ce061ce18 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/sql_fmt.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/sql_fmt.rs @@ -6,7 +6,7 @@ use sqruff_lib::{api::simple::get_simple_config, core::linter::core::Linter}; use xshell::Shell; use super::lint_utils::{get_unignored_files, IgnoredData, Target}; -use crate::messages::{msg_file_is_not_formatted, MSG_RUNNING_SQL_FMT_SPINNER}; +use crate::commands::dev::messages::{msg_file_is_not_formatted, MSG_RUNNING_SQL_FMT_SPINNER}; fn format_query(query: &str) -> anyhow::Result { let exclude_rules = vec!["LT12".to_string()]; // avoid adding newline before `$` character @@ -138,7 +138,7 @@ pub async fn format_sql(shell: Shell, check: bool) -> anyhow::Result<()> { let spinner = Spinner::new(MSG_RUNNING_SQL_FMT_SPINNER); let ignored_data = Some(IgnoredData { files: vec![], - dirs: vec!["zk_toolbox".to_string()], + dirs: vec!["zkstack_cli".to_string()], }); let rust_files = get_unignored_files(&shell, &Target::Rs, ignored_data)?; for file in rust_files { diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/fees.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/fees.rs similarity index 78% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/args/fees.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/fees.rs index 1337566e5369..83d505aa5753 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/fees.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/fees.rs @@ -1,7 +1,7 @@ use clap::Parser; use serde::{Deserialize, Serialize}; -use crate::messages::{MSG_NO_DEPS_HELP, MSG_NO_KILL_HELP}; +use crate::commands::dev::messages::{MSG_NO_DEPS_HELP, MSG_NO_KILL_HELP}; #[derive(Debug, Serialize, Deserialize, Parser)] pub struct FeesArgs { diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/integration.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/integration.rs similarity index 78% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/args/integration.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/integration.rs index 6cec40a2e338..625df0fc151e 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/integration.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/integration.rs @@ -1,7 +1,9 @@ use clap::Parser; use serde::{Deserialize, Serialize}; -use crate::messages::{MSG_NO_DEPS_HELP, MSG_TESTS_EXTERNAL_NODE_HELP, MSG_TEST_PATTERN_HELP}; +use crate::commands::dev::messages::{ + MSG_NO_DEPS_HELP, MSG_TESTS_EXTERNAL_NODE_HELP, MSG_TEST_PATTERN_HELP, +}; #[derive(Debug, Serialize, Deserialize, Parser)] pub struct IntegrationArgs { diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/mod.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/args/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/mod.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/recovery.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/recovery.rs similarity index 76% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/args/recovery.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/recovery.rs index 81cc58fbd9bd..cf4734fd82e7 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/recovery.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/recovery.rs @@ -1,7 +1,9 @@ use clap::Parser; use serde::{Deserialize, Serialize}; -use crate::messages::{MSG_NO_DEPS_HELP, MSG_NO_KILL_HELP, MSG_TESTS_RECOVERY_SNAPSHOT_HELP}; +use crate::commands::dev::messages::{ + MSG_NO_DEPS_HELP, MSG_NO_KILL_HELP, MSG_TESTS_RECOVERY_SNAPSHOT_HELP, +}; #[derive(Debug, Serialize, Deserialize, Parser)] pub struct RecoveryArgs { diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/revert.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/revert.rs similarity index 93% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/args/revert.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/revert.rs index 0154a4c0afd7..e4fb7fba2a97 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/revert.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/revert.rs @@ -1,6 +1,6 @@ use clap::Parser; -use crate::messages::{ +use crate::commands::dev::messages::{ MSG_NO_DEPS_HELP, MSG_NO_KILL_HELP, MSG_REVERT_TEST_ENABLE_CONSENSUS_HELP, MSG_TESTS_EXTERNAL_NODE_HELP, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/rust.rs similarity index 70% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/rust.rs index 2d94adc3f6a7..6ca277f6a2fc 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/rust.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/rust.rs @@ -1,6 +1,6 @@ use clap::Parser; -use crate::messages::MSG_TEST_RUST_OPTIONS_HELP; +use crate::commands::dev::messages::MSG_TEST_RUST_OPTIONS_HELP; #[derive(Debug, Parser)] pub struct RustArgs { diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/upgrade.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/upgrade.rs similarity index 72% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/args/upgrade.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/upgrade.rs index dd96957e9d3b..7b631b91e9a5 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/args/upgrade.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/args/upgrade.rs @@ -1,6 +1,6 @@ use clap::Parser; -use crate::messages::MSG_NO_DEPS_HELP; +use crate::commands::dev::messages::MSG_NO_DEPS_HELP; #[derive(Debug, Parser)] pub struct UpgradeArgs { diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/build.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/build.rs similarity index 100% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/build.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/build.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/db.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/db.rs similarity index 88% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/db.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/db.rs index d173bb951685..19f6307019b8 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/db.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/db.rs @@ -3,7 +3,7 @@ use std::path::Path; use common::{cmd::Cmd, db::wait_for_db, logger}; use xshell::{cmd, Shell}; -use crate::{commands::database, dals::Dal, messages::MSG_RESETTING_TEST_DATABASES}; +use crate::commands::dev::{commands::database, dals::Dal, messages::MSG_RESETTING_TEST_DATABASES}; pub async fn reset_test_databases( shell: &Shell, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/fees.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/fees.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/fees.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/fees.rs index e0b881a14dbb..e58a70e6b7cb 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/fees.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/fees.rs @@ -9,7 +9,7 @@ use super::{ args::fees::FeesArgs, utils::{build_contracts, install_and_build_dependencies, TS_INTEGRATION_PATH}, }; -use crate::{ +use crate::commands::dev::{ commands::test::utils::{TestWallets, TEST_WALLETS_PATH}, messages::{ MSG_CHAIN_NOT_FOUND_ERR, MSG_DESERIALIZE_TEST_WALLETS_ERR, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/integration.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/integration.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/integration.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/integration.rs index f1fdd91e0f6f..8e9e421c2f4e 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/integration.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/integration.rs @@ -12,7 +12,7 @@ use super::{ TS_INTEGRATION_PATH, }, }; -use crate::messages::{ +use crate::commands::dev::messages::{ msg_integration_tests_run, MSG_CHAIN_NOT_FOUND_ERR, MSG_DESERIALIZE_TEST_WALLETS_ERR, MSG_INTEGRATION_TESTS_RUN_SUCCESS, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/l1_contracts.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/l1_contracts.rs similarity index 86% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/l1_contracts.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/l1_contracts.rs index 0a1e1ec5203f..7d163daed671 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/l1_contracts.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/l1_contracts.rs @@ -2,7 +2,7 @@ use common::{cmd::Cmd, logger}; use config::EcosystemConfig; use xshell::{cmd, Shell}; -use crate::messages::MSG_L1_CONTRACTS_TEST_SUCCESS; +use crate::commands::dev::messages::MSG_L1_CONTRACTS_TEST_SUCCESS; pub fn run(shell: &Shell) -> anyhow::Result<()> { let ecosystem = EcosystemConfig::from_file(shell)?; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/loadtest.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/loadtest.rs similarity index 95% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/loadtest.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/loadtest.rs index ee307438ec97..72a8f97ff97d 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/loadtest.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/loadtest.rs @@ -3,7 +3,7 @@ use common::{cmd::Cmd, config::global_config, logger}; use config::EcosystemConfig; use xshell::{cmd, Shell}; -use crate::messages::MSG_CHAIN_NOT_FOUND_ERR; +use crate::commands::dev::messages::MSG_CHAIN_NOT_FOUND_ERR; pub fn run(shell: &Shell) -> anyhow::Result<()> { let ecosystem_config = EcosystemConfig::from_file(shell)?; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/mod.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/mod.rs index facd98850d4e..095e27652aa0 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/mod.rs @@ -5,7 +5,7 @@ use args::{ use clap::Subcommand; use xshell::Shell; -use crate::messages::{ +use crate::commands::dev::messages::{ MSG_BUILD_ABOUT, MSG_INTEGRATION_TESTS_ABOUT, MSG_L1_CONTRACTS_ABOUT, MSG_LOADTEST_ABOUT, MSG_PROVER_TEST_ABOUT, MSG_RECOVERY_TEST_ABOUT, MSG_REVERT_TEST_ABOUT, MSG_RUST_TEST_ABOUT, MSG_TEST_WALLETS_INFO, MSG_UPGRADE_TEST_ABOUT, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/prover.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/prover.rs similarity index 97% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/prover.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/prover.rs index f48b359a9357..200baf57215c 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/prover.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/prover.rs @@ -5,7 +5,7 @@ use config::EcosystemConfig; use url::Url; use xshell::{cmd, Shell}; -use crate::{ +use crate::commands::dev::{ commands::test::db::reset_test_databases, dals::{Dal, PROVER_DAL_PATH}, defaults::TEST_DATABASE_PROVER_URL, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/recovery.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/recovery.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/recovery.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/recovery.rs index 6a3e337d41e9..ae889969fd2c 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/recovery.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/recovery.rs @@ -9,7 +9,7 @@ use super::{ args::recovery::RecoveryArgs, utils::{install_and_build_dependencies, TestWallets, TEST_WALLETS_PATH}, }; -use crate::messages::{ +use crate::commands::dev::messages::{ MSG_CHAIN_NOT_FOUND_ERR, MSG_DESERIALIZE_TEST_WALLETS_ERR, MSG_RECOVERY_TEST_RUN_INFO, MSG_RECOVERY_TEST_RUN_SUCCESS, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/revert.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/revert.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/revert.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/revert.rs index 8b00e9d7f4d1..dc95c88db205 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/revert.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/revert.rs @@ -9,7 +9,7 @@ use super::{ args::revert::RevertArgs, utils::{install_and_build_dependencies, TestWallets, TEST_WALLETS_PATH}, }; -use crate::messages::{ +use crate::commands::dev::messages::{ msg_revert_tests_run, MSG_CHAIN_NOT_FOUND_ERR, MSG_DESERIALIZE_TEST_WALLETS_ERR, MSG_REVERT_TEST_RUN_INFO, MSG_REVERT_TEST_RUN_SUCCESS, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/rust.rs similarity index 94% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/rust.rs index 7011e0f0f874..8c0c707f6a2e 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/rust.rs @@ -7,7 +7,7 @@ use url::Url; use xshell::{cmd, Shell}; use super::args::rust::RustArgs; -use crate::{ +use crate::commands::dev::{ commands::test::db::reset_test_databases, dals::{Dal, CORE_DAL_PATH, PROVER_DAL_PATH}, defaults::{TEST_DATABASE_PROVER_URL, TEST_DATABASE_SERVER_URL}, @@ -75,8 +75,8 @@ pub async fn run(shell: &Shell, args: RustArgs) -> anyhow::Result<()> { .env("TEST_PROVER_DATABASE_URL", test_prover_url); cmd.run()?; - // Run unit tests for zk_toolbox - let _dir_guard = shell.push_dir(link_to_code.join("zk_toolbox")); + // Run unit tests for ZK Stack CLI + let _dir_guard = shell.push_dir(link_to_code.join("zkstack_cli")); Cmd::new(cmd!(shell, "cargo nextest run --release")) .with_force_run() .run()?; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/upgrade.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/upgrade.rs similarity index 91% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/upgrade.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/upgrade.rs index 9bd04b81ef34..707e0086ed15 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/upgrade.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/upgrade.rs @@ -3,7 +3,7 @@ use config::EcosystemConfig; use xshell::{cmd, Shell}; use super::{args::upgrade::UpgradeArgs, utils::install_and_build_dependencies}; -use crate::messages::{MSG_UPGRADE_TEST_RUN_INFO, MSG_UPGRADE_TEST_RUN_SUCCESS}; +use crate::commands::dev::messages::{MSG_UPGRADE_TEST_RUN_INFO, MSG_UPGRADE_TEST_RUN_SUCCESS}; const UPGRADE_TESTS_PATH: &str = "core/tests/upgrade-test"; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/utils.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/utils.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/utils.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/utils.rs index d980490c3d58..bcd524bd2cb0 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/utils.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/utils.rs @@ -10,7 +10,7 @@ use ethers::{ use serde::Deserialize; use xshell::{cmd, Shell}; -use crate::messages::{ +use crate::commands::dev::messages::{ MSG_INTEGRATION_TESTS_BUILDING_CONTRACTS, MSG_INTEGRATION_TESTS_BUILDING_DEPENDENCIES, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/wallet.rs b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/wallet.rs similarity index 96% rename from zk_toolbox/crates/zk_supervisor/src/commands/test/wallet.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/commands/test/wallet.rs index 62f32b50d559..6953014bf92b 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/wallet.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/commands/test/wallet.rs @@ -6,7 +6,7 @@ use config::EcosystemConfig; use xshell::Shell; use super::utils::{TestWallets, TEST_WALLETS_PATH}; -use crate::messages::{ +use crate::commands::dev::messages::{ MSG_DESERIALIZE_TEST_WALLETS_ERR, MSG_TEST_WALLETS_INFO, MSG_WALLETS_TEST_SUCCESS, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/consts.rs b/zkstack_cli/crates/zkstack/src/commands/dev/consts.rs similarity index 100% rename from zk_toolbox/crates/zk_supervisor/src/consts.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/consts.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/dals.rs b/zkstack_cli/crates/zkstack/src/commands/dev/dals.rs similarity index 99% rename from zk_toolbox/crates/zk_supervisor/src/dals.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/dals.rs index b998eb4301d0..9626edfed732 100644 --- a/zk_toolbox/crates/zk_supervisor/src/dals.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/dals.rs @@ -3,7 +3,7 @@ use config::{EcosystemConfig, SecretsConfig}; use url::Url; use xshell::Shell; -use crate::{ +use super::{ commands::database::args::DalUrls, messages::{MSG_CHAIN_NOT_FOUND_ERR, MSG_DATABASE_MUST_BE_PRESENTED}, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/defaults.rs b/zkstack_cli/crates/zkstack/src/commands/dev/defaults.rs similarity index 100% rename from zk_toolbox/crates/zk_supervisor/src/defaults.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/defaults.rs diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zkstack_cli/crates/zkstack/src/commands/dev/messages.rs similarity index 98% rename from zk_toolbox/crates/zk_supervisor/src/messages.rs rename to zkstack_cli/crates/zkstack/src/commands/dev/messages.rs index 85c0695aa7c5..c7e639f8e87c 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zkstack_cli/crates/zkstack/src/commands/dev/messages.rs @@ -1,12 +1,8 @@ -use crate::commands::lint_utils::Target; +use super::commands::lint_utils::Target; // Ecosystem related messages pub(super) const MSG_CHAIN_NOT_FOUND_ERR: &str = "Chain not found"; -pub(super) fn msg_global_chain_does_not_exist(chain: &str, available_chains: &str) -> String { - format!("Chain with name {chain} doesnt exist, please choose one of: {available_chains}") -} - // Subcommands help pub(super) const MSG_GENERATE_GENESIS_ABOUT: &str = "Generate new genesis file based on current contracts"; diff --git a/zkstack_cli/crates/zkstack/src/commands/dev/mod.rs b/zkstack_cli/crates/zkstack/src/commands/dev/mod.rs new file mode 100644 index 000000000000..9272436a9b9d --- /dev/null +++ b/zkstack_cli/crates/zkstack/src/commands/dev/mod.rs @@ -0,0 +1,65 @@ +use clap::Subcommand; +use xshell::Shell; + +use self::commands::{ + clean::CleanCommands, config_writer::ConfigWriterArgs, contracts::ContractsArgs, + database::DatabaseCommands, fmt::FmtArgs, lint::LintArgs, prover::ProverCommands, + send_transactions::args::SendTransactionsArgs, snapshot::SnapshotCommands, test::TestCommands, +}; +use crate::commands::dev::messages::{ + MSG_CONFIG_WRITER_ABOUT, MSG_CONTRACTS_ABOUT, MSG_GENERATE_GENESIS_ABOUT, + MSG_PROVER_VERSION_ABOUT, MSG_SEND_TXNS_ABOUT, MSG_SUBCOMMAND_CLEAN, + MSG_SUBCOMMAND_DATABASE_ABOUT, MSG_SUBCOMMAND_FMT_ABOUT, MSG_SUBCOMMAND_LINT_ABOUT, + MSG_SUBCOMMAND_SNAPSHOTS_CREATOR_ABOUT, MSG_SUBCOMMAND_TESTS_ABOUT, +}; + +mod commands; +mod consts; +mod dals; +mod defaults; +mod messages; + +#[derive(Subcommand, Debug)] +pub enum DevCommands { + #[command(subcommand, about = MSG_SUBCOMMAND_DATABASE_ABOUT, alias = "db")] + Database(DatabaseCommands), + #[command(subcommand, about = MSG_SUBCOMMAND_TESTS_ABOUT, alias = "t")] + Test(TestCommands), + #[command(subcommand, about = MSG_SUBCOMMAND_CLEAN)] + Clean(CleanCommands), + #[command(subcommand, about = MSG_SUBCOMMAND_SNAPSHOTS_CREATOR_ABOUT)] + Snapshot(SnapshotCommands), + #[command(about = MSG_SUBCOMMAND_LINT_ABOUT, alias = "l")] + Lint(LintArgs), + #[command(about = MSG_SUBCOMMAND_FMT_ABOUT)] + Fmt(FmtArgs), + #[command(subcommand, about = MSG_PROVER_VERSION_ABOUT)] + Prover(ProverCommands), + #[command(about = MSG_CONTRACTS_ABOUT)] + Contracts(ContractsArgs), + #[command(about = MSG_CONFIG_WRITER_ABOUT, alias = "o")] + ConfigWriter(ConfigWriterArgs), + #[command(about = MSG_SEND_TXNS_ABOUT)] + SendTransactions(SendTransactionsArgs), + #[command(about = MSG_GENERATE_GENESIS_ABOUT, alias = "genesis")] + GenerateGenesis, +} + +pub async fn run(shell: &Shell, args: DevCommands) -> anyhow::Result<()> { + match args { + DevCommands::Database(command) => commands::database::run(shell, command).await?, + DevCommands::Test(command) => commands::test::run(shell, command).await?, + DevCommands::Clean(command) => commands::clean::run(shell, command)?, + DevCommands::Snapshot(command) => commands::snapshot::run(shell, command).await?, + DevCommands::Lint(args) => commands::lint::run(shell, args)?, + DevCommands::Fmt(args) => commands::fmt::run(shell.clone(), args).await?, + DevCommands::Prover(command) => commands::prover::run(shell, command).await?, + DevCommands::Contracts(args) => commands::contracts::run(shell, args)?, + DevCommands::ConfigWriter(args) => commands::config_writer::run(shell, args)?, + DevCommands::SendTransactions(args) => { + commands::send_transactions::run(shell, args).await? + } + DevCommands::GenerateGenesis => commands::genesis::run(shell).await?, + } + Ok(()) +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/build_transactions.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/args/build_transactions.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/change_default.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/change_default.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/change_default.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/args/change_default.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/create.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/args/create.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/init.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/args/init.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/args/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/args/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/build_transactions.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/build_transactions.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/change_default.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/change_default.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/change_default.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/change_default.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/common.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/common.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/create.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/create.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/create_configs.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/create_configs.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/create_configs.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/create_configs.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/setup_observability.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/setup_observability.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/setup_observability.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/setup_observability.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/utils.rs b/zkstack_cli/crates/zkstack/src/commands/ecosystem/utils.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/utils.rs rename to zkstack_cli/crates/zkstack/src/commands/ecosystem/utils.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/explorer/backend.rs b/zkstack_cli/crates/zkstack/src/commands/explorer/backend.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/explorer/backend.rs rename to zkstack_cli/crates/zkstack/src/commands/explorer/backend.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/explorer/init.rs b/zkstack_cli/crates/zkstack/src/commands/explorer/init.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/explorer/init.rs rename to zkstack_cli/crates/zkstack/src/commands/explorer/init.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/explorer/mod.rs b/zkstack_cli/crates/zkstack/src/commands/explorer/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/explorer/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/explorer/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/explorer/run.rs b/zkstack_cli/crates/zkstack/src/commands/explorer/run.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/explorer/run.rs rename to zkstack_cli/crates/zkstack/src/commands/explorer/run.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/external_node/args/mod.rs b/zkstack_cli/crates/zkstack/src/commands/external_node/args/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/external_node/args/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/external_node/args/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/external_node/args/prepare_configs.rs b/zkstack_cli/crates/zkstack/src/commands/external_node/args/prepare_configs.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/external_node/args/prepare_configs.rs rename to zkstack_cli/crates/zkstack/src/commands/external_node/args/prepare_configs.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/external_node/args/run.rs b/zkstack_cli/crates/zkstack/src/commands/external_node/args/run.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/external_node/args/run.rs rename to zkstack_cli/crates/zkstack/src/commands/external_node/args/run.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/external_node/init.rs b/zkstack_cli/crates/zkstack/src/commands/external_node/init.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/external_node/init.rs rename to zkstack_cli/crates/zkstack/src/commands/external_node/init.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/external_node/mod.rs b/zkstack_cli/crates/zkstack/src/commands/external_node/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/external_node/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/external_node/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/external_node/prepare_configs.rs b/zkstack_cli/crates/zkstack/src/commands/external_node/prepare_configs.rs similarity index 82% rename from zk_toolbox/crates/zk_inception/src/commands/external_node/prepare_configs.rs rename to zkstack_cli/crates/zkstack/src/commands/external_node/prepare_configs.rs index 5ab859d17f0a..d714a0f8e843 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/external_node/prepare_configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/external_node/prepare_configs.rs @@ -6,12 +6,12 @@ use config::{ external_node::ENConfig, set_rocks_db_config, traits::{FileConfigWithDefaultName, SaveConfigWithBasePath}, - ChainConfig, EcosystemConfig, GeneralConfig, SecretsConfig, DEFAULT_CONSENSUS_PORT, + ChainConfig, EcosystemConfig, GeneralConfig, SecretsConfig, }; use xshell::Shell; use zksync_basic_types::url::SensitiveUrl; use zksync_config::configs::{ - consensus::{ConsensusSecrets, NodeSecretKey, Secret}, + consensus::{ConsensusConfig, ConsensusSecrets, NodeSecretKey, Secret}, DatabaseSecrets, L1Secrets, }; use zksync_consensus_crypto::TextFmt; @@ -19,14 +19,13 @@ use zksync_consensus_roles as roles; use crate::{ commands::external_node::args::prepare_configs::{PrepareConfigArgs, PrepareConfigFinal}, - defaults::PORT_RANGE_END, messages::{ msg_preparing_en_config_is_done, MSG_CHAIN_NOT_INITIALIZED, MSG_CONSENSUS_CONFIG_MISSING_ERR, MSG_CONSENSUS_SECRETS_MISSING_ERR, MSG_CONSENSUS_SECRETS_NODE_KEY_MISSING_ERR, MSG_PREPARING_EN_CONFIGS, }, utils::{ - consensus::{get_consensus_config, node_public_key}, + consensus::node_public_key, ports::EcosystemPortsScanner, rocks_db::{recreate_rocksdb_dirs, RocksDBDirOption}, }, @@ -79,19 +78,12 @@ fn prepare_configs( bridge_addresses_refresh_interval_sec: None, }; let mut general_en = general.clone(); + general_en.consensus_config = None; let main_node_consensus_config = general .consensus_config .context(MSG_CONSENSUS_CONFIG_MISSING_ERR)?; - - // TODO: This is a temporary solution. We should allocate consensus port using `EcosystemPorts::allocate_ports_in_yaml` - ports.add_port_info( - main_node_consensus_config.server_addr.port(), - "Main node consensus".to_string(), - ); - let offset = ((config.id - 1) * 100) as u16; - let consensus_port_range = DEFAULT_CONSENSUS_PORT + offset..PORT_RANGE_END; - let consensus_port = ports.allocate_port(consensus_port_range, "Consensus".to_string())?; + let mut en_consensus_config = main_node_consensus_config.clone(); let mut gossip_static_outbound = BTreeMap::new(); let main_node_public_key = node_public_key( @@ -101,13 +93,8 @@ fn prepare_configs( .context(MSG_CONSENSUS_SECRETS_MISSING_ERR)?, )? .context(MSG_CONSENSUS_SECRETS_NODE_KEY_MISSING_ERR)?; - gossip_static_outbound.insert(main_node_public_key, main_node_consensus_config.public_addr); - - let en_consensus_config = - get_consensus_config(config, consensus_port, None, Some(gossip_static_outbound))?; - general_en.consensus_config = Some(en_consensus_config.clone()); - en_consensus_config.save_with_base_path(shell, en_configs_path)?; + en_consensus_config.gossip_static_outbound = gossip_static_outbound; // Set secrets config let node_key = roles::node::SecretKey::generate().encode(); @@ -128,16 +115,25 @@ fn prepare_configs( }), data_availability: None, }; - secrets.save_with_base_path(shell, en_configs_path)?; + let dirs = recreate_rocksdb_dirs(shell, &config.rocks_db_path, RocksDBDirOption::ExternalNode)?; set_rocks_db_config(&mut general_en, dirs)?; + general_en.save_with_base_path(shell, en_configs_path)?; en_config.save_with_base_path(shell, en_configs_path)?; + en_consensus_config.save_with_base_path(shell, en_configs_path)?; + secrets.save_with_base_path(shell, en_configs_path)?; + let offset = 0; // This is zero because general_en ports already have a chain offset ports.allocate_ports_in_yaml( shell, &GeneralConfig::get_path_with_base_path(en_configs_path), - 0, // This is zero because general_en ports already have a chain offset + offset, + )?; + ports.allocate_ports_in_yaml( + shell, + &ConsensusConfig::get_path_with_base_path(en_configs_path), + offset, )?; Ok(()) diff --git a/zk_toolbox/crates/zk_inception/src/commands/external_node/run.rs b/zkstack_cli/crates/zkstack/src/commands/external_node/run.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/external_node/run.rs rename to zkstack_cli/crates/zkstack/src/commands/external_node/run.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/mod.rs b/zkstack_cli/crates/zkstack/src/commands/mod.rs similarity index 94% rename from zk_toolbox/crates/zk_inception/src/commands/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/mod.rs index 78a46797602f..c46400cc8657 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/mod.rs @@ -3,6 +3,7 @@ pub mod chain; pub mod consensus; pub mod containers; pub mod contract_verifier; +pub mod dev; pub mod ecosystem; pub mod explorer; pub mod external_node; diff --git a/zk_toolbox/crates/zk_inception/src/commands/portal.rs b/zkstack_cli/crates/zkstack/src/commands/portal.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/portal.rs rename to zkstack_cli/crates/zkstack/src/commands/portal.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/compressor_keys.rs b/zkstack_cli/crates/zkstack/src/commands/prover/args/compressor_keys.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/args/compressor_keys.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/args/compressor_keys.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs b/zkstack_cli/crates/zkstack/src/commands/prover/args/init.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/args/init.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init_bellman_cuda.rs b/zkstack_cli/crates/zkstack/src/commands/prover/args/init_bellman_cuda.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/args/init_bellman_cuda.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/args/init_bellman_cuda.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/mod.rs b/zkstack_cli/crates/zkstack/src/commands/prover/args/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/args/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/args/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/run.rs b/zkstack_cli/crates/zkstack/src/commands/prover/args/run.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/args/run.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/args/run.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/setup_keys.rs b/zkstack_cli/crates/zkstack/src/commands/prover/args/setup_keys.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/args/setup_keys.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/args/setup_keys.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/compressor_keys.rs b/zkstack_cli/crates/zkstack/src/commands/prover/compressor_keys.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/compressor_keys.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/compressor_keys.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/gcs.rs b/zkstack_cli/crates/zkstack/src/commands/prover/gcs.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/gcs.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/gcs.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs b/zkstack_cli/crates/zkstack/src/commands/prover/init.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/init.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/init.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/init_bellman_cuda.rs b/zkstack_cli/crates/zkstack/src/commands/prover/init_bellman_cuda.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/init_bellman_cuda.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/init_bellman_cuda.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/mod.rs b/zkstack_cli/crates/zkstack/src/commands/prover/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/mod.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/run.rs b/zkstack_cli/crates/zkstack/src/commands/prover/run.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/run.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/run.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/setup_keys.rs b/zkstack_cli/crates/zkstack/src/commands/prover/setup_keys.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/prover/setup_keys.rs rename to zkstack_cli/crates/zkstack/src/commands/prover/setup_keys.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/server.rs b/zkstack_cli/crates/zkstack/src/commands/server.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/server.rs rename to zkstack_cli/crates/zkstack/src/commands/server.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/update.rs b/zkstack_cli/crates/zkstack/src/commands/update.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/commands/update.rs rename to zkstack_cli/crates/zkstack/src/commands/update.rs diff --git a/zk_toolbox/crates/zk_inception/src/consts.rs b/zkstack_cli/crates/zkstack/src/consts.rs similarity index 68% rename from zk_toolbox/crates/zk_inception/src/consts.rs rename to zkstack_cli/crates/zkstack/src/consts.rs index 9f81847e3336..df27d2f02d2c 100644 --- a/zk_toolbox/crates/zk_inception/src/consts.rs +++ b/zkstack_cli/crates/zkstack/src/consts.rs @@ -1,5 +1,3 @@ -use std::net::{IpAddr, Ipv4Addr}; - pub const AMOUNT_FOR_DISTRIBUTION_TO_WALLETS: u128 = 1000000000000000000000; pub const MINIMUM_BALANCE_FOR_WALLET: u128 = 5000000000000000000; @@ -12,27 +10,6 @@ pub const DEFAULT_UNSIGNED_TRANSACTIONS_DIR: &str = "transactions"; pub const BELLMAN_CUDA_DIR: &str = "era-bellman-cuda"; pub const L2_BASE_TOKEN_ADDRESS: &str = "0x000000000000000000000000000000000000800A"; -#[allow(non_upper_case_globals)] -const kB: usize = 1024; - -/// Max payload size for consensus in bytes -pub const MAX_PAYLOAD_SIZE: usize = 2_500_000; -/// Max batch size for consensus in bytes -/// Compute a default batch size, so operators are not caught out by the missing setting -/// while we're still working on batch syncing. The batch interval is ~1 minute, -/// so there will be ~60 blocks, and an Ethereum Merkle proof is ~1kB, but under high -/// traffic there can be thousands of huge transactions that quickly fill up blocks -/// and there could be more blocks in a batch then expected. We chose a generous -/// limit so as not to prevent any legitimate batch from being transmitted. -pub const MAX_BATCH_SIZE: usize = MAX_PAYLOAD_SIZE * 5000 + kB; -/// Gossip dynamic inbound limit for consensus -pub const GOSSIP_DYNAMIC_INBOUND_LIMIT: usize = 100; - -/// Public address for consensus -pub const CONSENSUS_PUBLIC_ADDRESS_HOST: IpAddr = IpAddr::V4(Ipv4Addr::UNSPECIFIED); -/// Server address for consensus -pub const CONSENSUS_SERVER_ADDRESS_HOST: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST); - /// Path to the JS runtime config for the block-explorer-app docker container to be mounted to pub const EXPLORER_APP_DOCKER_CONFIG_PATH: &str = "/usr/src/app/packages/app/dist/config.js"; pub const EXPLORER_APP_DOCKER_IMAGE: &str = "matterlabs/block-explorer-app"; diff --git a/zk_toolbox/crates/zk_inception/src/defaults.rs b/zkstack_cli/crates/zkstack/src/defaults.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/defaults.rs rename to zkstack_cli/crates/zkstack/src/defaults.rs diff --git a/zk_toolbox/crates/zk_inception/src/external_node.rs b/zkstack_cli/crates/zkstack/src/external_node.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/external_node.rs rename to zkstack_cli/crates/zkstack/src/external_node.rs diff --git a/zk_toolbox/crates/zk_inception/src/main.rs b/zkstack_cli/crates/zkstack/src/main.rs similarity index 96% rename from zk_toolbox/crates/zk_inception/src/main.rs rename to zkstack_cli/crates/zkstack/src/main.rs index a305ca053b7c..987de555ecf6 100644 --- a/zk_toolbox/crates/zk_inception/src/main.rs +++ b/zkstack_cli/crates/zkstack/src/main.rs @@ -2,6 +2,7 @@ use clap::{command, Parser, Subcommand}; use commands::{ args::{ContainersArgs, UpdateArgs}, contract_verifier::ContractVerifierCommands, + dev::DevCommands, }; use common::{ check_general_prerequisites, @@ -46,6 +47,9 @@ pub enum InceptionSubcommands { /// Chain related commands #[command(subcommand, alias = "c")] Chain(Box), + /// Chain related commands + #[command(subcommand)] + Dev(DevCommands), /// Prover related commands #[command(subcommand, alias = "p")] Prover(ProverCommands), @@ -123,6 +127,7 @@ async fn run_subcommand(inception_args: Inception, shell: &Shell) -> anyhow::Res match inception_args.command { InceptionSubcommands::Ecosystem(args) => commands::ecosystem::run(shell, *args).await?, InceptionSubcommands::Chain(args) => commands::chain::run(shell, *args).await?, + InceptionSubcommands::Dev(args) => commands::dev::run(shell, args).await?, InceptionSubcommands::Prover(args) => commands::prover::run(shell, args).await?, InceptionSubcommands::Server(args) => commands::server::run(shell, args)?, InceptionSubcommands::Containers(args) => commands::containers::run(shell, args)?, diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zkstack_cli/crates/zkstack/src/messages.rs similarity index 99% rename from zk_toolbox/crates/zk_inception/src/messages.rs rename to zkstack_cli/crates/zkstack/src/messages.rs index ebdcf7378a44..d1d86db83989 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zkstack_cli/crates/zkstack/src/messages.rs @@ -296,7 +296,7 @@ pub(super) const MSG_EXPLORER_FAILED_TO_RUN_DOCKER_ERR: &str = pub(super) const MSG_EXPLORER_FAILED_TO_CREATE_CONFIG_ERR: &str = "Failed to create explorer config"; pub(super) const MSG_EXPLORER_FAILED_TO_FIND_ANY_CHAIN_ERR: &str = - "Failed to find any valid chain to run explorer for. Did you run `zk_inception explorer init`?"; + "Failed to find any valid chain to run explorer for. Did you run `zkstack explorer init`?"; pub(super) const MSG_EXPLORER_INITIALIZED: &str = "Explorer has been initialized successfully"; pub(super) fn msg_explorer_initializing_database_for(chain: &str) -> String { format!("Initializing explorer database for {chain} chain") @@ -311,7 +311,7 @@ pub(super) fn msg_explorer_starting_on(host: &str, port: u16) -> String { format!("Starting explorer on http://{host}:{port}") } pub(super) fn msg_explorer_chain_not_initialized(chain: &str) -> String { - format!("Chain {chain} is not initialized for explorer: run `zk_inception explorer init --chain {chain}` first") + format!("Chain {chain} is not initialized for explorer: run `zkstack explorer init --chain {chain}` first") } /// Forge utils related messages diff --git a/zk_toolbox/crates/zk_inception/src/utils/consensus.rs b/zkstack_cli/crates/zkstack/src/utils/consensus.rs similarity index 70% rename from zk_toolbox/crates/zk_inception/src/utils/consensus.rs rename to zkstack_cli/crates/zkstack/src/utils/consensus.rs index 2979b4df0c19..946d28a33fbd 100644 --- a/zk_toolbox/crates/zk_inception/src/utils/consensus.rs +++ b/zkstack_cli/crates/zkstack/src/utils/consensus.rs @@ -1,24 +1,14 @@ -use std::{ - collections::{BTreeMap, BTreeSet}, - net::SocketAddr, -}; - use anyhow::Context as _; use config::ChainConfig; use secrecy::{ExposeSecret, Secret}; use zksync_config::configs::consensus::{ - AttesterPublicKey, AttesterSecretKey, ConsensusConfig, ConsensusSecrets, GenesisSpec, Host, - NodePublicKey, NodeSecretKey, ProtocolVersion, ValidatorPublicKey, ValidatorSecretKey, - WeightedAttester, WeightedValidator, + AttesterPublicKey, AttesterSecretKey, ConsensusSecrets, GenesisSpec, NodePublicKey, + NodeSecretKey, ProtocolVersion, ValidatorPublicKey, ValidatorSecretKey, WeightedAttester, + WeightedValidator, }; use zksync_consensus_crypto::{Text, TextFmt}; use zksync_consensus_roles::{attester, node, validator}; -use crate::consts::{ - CONSENSUS_PUBLIC_ADDRESS_HOST, CONSENSUS_SERVER_ADDRESS_HOST, GOSSIP_DYNAMIC_INBOUND_LIMIT, - MAX_BATCH_SIZE, MAX_PAYLOAD_SIZE, -}; - pub(crate) fn parse_attester_committee( attesters: &[WeightedAttester], ) -> anyhow::Result { @@ -48,32 +38,6 @@ pub struct ConsensusPublicKeys { attester_key: attester::PublicKey, } -pub fn get_consensus_config( - chain_config: &ChainConfig, - consensus_port: u16, - consensus_keys: Option, - gossip_static_outbound: Option>, -) -> anyhow::Result { - let genesis_spec = - consensus_keys.map(|consensus_keys| get_genesis_specs(chain_config, &consensus_keys)); - - let public_addr = SocketAddr::new(CONSENSUS_PUBLIC_ADDRESS_HOST, consensus_port); - let server_addr = SocketAddr::new(CONSENSUS_SERVER_ADDRESS_HOST, consensus_port); - - Ok(ConsensusConfig { - server_addr, - public_addr: Host(public_addr.encode()), - genesis_spec, - max_payload_size: MAX_PAYLOAD_SIZE, - gossip_dynamic_inbound_limit: GOSSIP_DYNAMIC_INBOUND_LIMIT, - max_batch_size: MAX_BATCH_SIZE, - gossip_static_inbound: BTreeSet::new(), - gossip_static_outbound: gossip_static_outbound.unwrap_or_default(), - rpc: None, - debug_page_addr: None, - }) -} - pub fn generate_consensus_keys() -> ConsensusSecretKeys { ConsensusSecretKeys { validator_key: validator::SecretKey::generate(), diff --git a/zk_toolbox/crates/zk_inception/src/utils/forge.rs b/zkstack_cli/crates/zkstack/src/utils/forge.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/utils/forge.rs rename to zkstack_cli/crates/zkstack/src/utils/forge.rs diff --git a/zk_toolbox/crates/zk_inception/src/utils/mod.rs b/zkstack_cli/crates/zkstack/src/utils/mod.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/utils/mod.rs rename to zkstack_cli/crates/zkstack/src/utils/mod.rs diff --git a/zk_toolbox/crates/zk_inception/src/utils/ports.rs b/zkstack_cli/crates/zkstack/src/utils/ports.rs similarity index 97% rename from zk_toolbox/crates/zk_inception/src/utils/ports.rs rename to zkstack_cli/crates/zkstack/src/utils/ports.rs index 018fb79f345d..04c8cef5ff59 100644 --- a/zk_toolbox/crates/zk_inception/src/utils/ports.rs +++ b/zkstack_cli/crates/zkstack/src/utils/ports.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, fmt, ops::Range, path::Path}; +use std::{collections::HashMap, fmt, net::SocketAddr, ops::Range, path::Path}; use anyhow::{bail, Context, Result}; use config::{ @@ -109,6 +109,12 @@ impl EcosystemPorts { } } } + } else if key.as_str().map(|s| s.ends_with("addr")).unwrap_or(false) { + let socket_addr = val.as_str().unwrap().parse::()?; + if let Some(new_port) = updated_ports.get(&socket_addr.port()) { + let new_socket_addr = SocketAddr::new(socket_addr.ip(), *new_port); + *val = Value::String(new_socket_addr.to_string()); + } } } // Continue traversing diff --git a/zk_toolbox/crates/zk_inception/src/utils/rocks_db.rs b/zkstack_cli/crates/zkstack/src/utils/rocks_db.rs similarity index 100% rename from zk_toolbox/crates/zk_inception/src/utils/rocks_db.rs rename to zkstack_cli/crates/zkstack/src/utils/rocks_db.rs diff --git a/zk_toolbox/rust-toolchain b/zkstack_cli/rust-toolchain similarity index 100% rename from zk_toolbox/rust-toolchain rename to zkstack_cli/rust-toolchain diff --git a/zkstack_cli/zkstackup/README.md b/zkstack_cli/zkstackup/README.md new file mode 100644 index 000000000000..4977c4641e09 --- /dev/null +++ b/zkstack_cli/zkstackup/README.md @@ -0,0 +1,70 @@ +# zkstackup - ZK Stack CLI Installer + +`zkstackup` is a script designed to simplify the installation of +[ZK Stack CLI](https://github.com/matter-labs/zksync-era/tree/main/zkstack_cli). It allows you to install the tool from +a local directory or directly from a GitHub repository. + +## Getting Started + +To install `zkstackup`, run the following command: + +```bash +curl -L https://raw.githubusercontent.com/matter-labs/zksync-era/main/zkstack_cli/zkstackup/install | bash +``` + +After installing `zkstackup`, you can use it to install `zkstack_cli` with: + +```bash +zkstackup +``` + +## Usage + +The `zkstackup` script provides various options for installing ZK Stack CLI: + +### Options + +- `-p, --path ` + Specify a local path to install ZK Stack CLI from. This option is ignored if `--repo` is provided. + +- `-r, --repo ` + GitHub repository to install from (e.g., "matter-labs/zksync-era"). Defaults to "matter-labs/zksync-era". + +- `-b, --branch ` + Git branch to use when installing from a repository. Ignored if `--commit` or `--version` is provided. + +- `-c, --commit ` + Git commit hash to use when installing from a repository. Ignored if `--branch` or `--version` is provided. + +- `-v, --version ` + Git tag to use when installing from a repository. Ignored if `--branch` or `--commit` is provided. + +### Local Installation + +If you provide a local path using the `-p` or `--path` option, `zkstackup` will install ZK Stack CLI from that +directory. Note that repository-specific arguments (`--repo`, `--branch`, `--commit`, `--version`) will be ignored in +this case to preserve git state. + +### Repository Installation + +By default, `zkstackup` installs ZK Stack CLI from the "matter-labs/zksync-era" GitHub repository. You can specify a +different repository, branch, commit, or version using the respective options. If multiple arguments are provided, +`zkstackup` will prioritize them as follows: + +- `--version` +- `--commit` +- `--branch` + +### Examples + +**Install from a GitHub repository with a specific version:** + +```bash +zkstackup --repo matter-labs/zksync-era --version 0.1.1 +``` + +**Install from a local path:** + +```bash +zkstackup --path /path/to/local/zkstack_cli +``` diff --git a/zkstack_cli/zkstackup/install b/zkstack_cli/zkstackup/install new file mode 100755 index 000000000000..f20ba4dd545a --- /dev/null +++ b/zkstack_cli/zkstackup/install @@ -0,0 +1,121 @@ +#!/usr/bin/env bash +set -eo pipefail + +BIN_URL="https://raw.githubusercontent.com/matter-labs/zksync-era/main/zkstack_cli/zkstackup/zkstackup" + +HOME_DIR=${XDG_CONFIG_HOME:-$HOME} +BIN_DIR="$HOME_DIR/.local/bin" +BIN_PATH="$BIN_DIR/zkstackup" + +main() { + parse_args "$@" + + mkdir -p "$BIN_DIR" + + if [ -n "$ZKSTACKUP_PATH" ]; then + cp -r "$ZKSTACKUP_PATH" "$BIN_DIR" + else + curl -sSfL "$BIN_URL" -o "$BIN_PATH" + fi + + chmod +x "$BIN_PATH" + echo "zkstackup: successfully installed in ${BIN_DIR}." + + add_bin_folder_to_path +} + +add_bin_folder_to_path() { + if [[ ":$PATH:" == *":${BIN_DIR}:"* ]]; then + echo "zkstackup: found ${BIN_DIR} in PATH" + exit 0 + fi + + case $SHELL in + */zsh) + PROFILE="${ZDOTDIR-"$HOME"}/.zshenv" + ;; + */bash) + PROFILE="$HOME/.bashrc" + ;; + */fish) + PROFILE="$HOME/.config/fish/config.fish" + ;; + */ash) + PROFILE="$HOME/.profile" + ;; + *) + echo "zkstackup: could not detect shell, manually add ${BIN_DIR} to your PATH." + exit 1 + ;; + esac + + if [[ ! -f "$PROFILE" ]]; then + echo "zkstackup: Profile file $PROFILE does not exist, creating it." + touch "$PROFILE" + fi + + if [[ "$SHELL" == *"/fish"* ]]; then + echo -e "\n# Added by zkstackup\nfish_add_path -a $BIN_DIR" >>"$PROFILE" + echo "zkstackup: Added $BIN_DIR to PATH in $PROFILE using fish_add_path." + else + echo -e "\n# Added by zkstackup\nexport PATH=\"\$PATH:$BIN_DIR\"" >>"$PROFILE" + echo "zkstackup: Added $BIN_DIR to PATH in $PROFILE." + fi + + echo + echo "Added zkstackup to PATH." + echo "Run 'source $PROFILE' or start a new terminal session to use zkstackup." + echo "Then run 'zkstackup' to install ZK Stack CLI." +} + +parse_args() { + while [[ $# -gt 0 ]]; do + case $1 in + --) + shift + break + ;; + -p | --path) + shift + ZKSTACKUP_PATH=$1 + ;; + -l | --local) + ZKSTACKUP_PATH="./" + ;; + -g | --global) + BIN_DIR="/usr/local/bin" + BIN_PATH="$BIN_DIR/zkstackup" + ;; + -h | --help) + usage + exit 0 + ;; + *) + err "Unknown argument: $1" + usage + exit 1 + ;; + esac + shift + done +} + + +usage() { + cat < Specify a local path to install zkstackup from. + -l, --local Install zkstackup from the current directory. + -g, --global Install zkstackup for all users. + -h, --help Show this help message and exit. + +Examples: + $(basename "$0") --path /path/to/zkstackup +EOF +} + +main "$@" diff --git a/zkstack_cli/zkstackup/zkstackup b/zkstack_cli/zkstackup/zkstackup new file mode 100755 index 000000000000..20a061620f9a --- /dev/null +++ b/zkstack_cli/zkstackup/zkstackup @@ -0,0 +1,273 @@ +#!/usr/bin/env bash +set -eo pipefail + +HOME_DIR=${XDG_CONFIG_HOME:-$HOME} +LOCAL_DIR=${LOCAL_DIR:-"$HOME_DIR/.local"} +BIN_DIR="$LOCAL_DIR/bin" + +BINS=() + +main() { + parse_args "$@" + + zkstack_banner + + check_prerequisites + mkdir -p "$BIN_DIR" + + BINS+=(zkstack) + + if [ -n "$ZKSTACKUP_PATH" ]; then + install_local + else + install_from_repo + fi + + zkstack_banner + + add_bin_folder_to_path + + for bin in "${BINS[@]}"; do + success "Installed $bin to $BIN_DIR/$bin" + done +} + +PREREQUISITES=(cargo git) + +check_prerequisites() { + say "Checking prerequisites" + + failed_prerequisites=() + for prerequisite in "${PREREQUISITES[@]}"; do + if ! check_prerequisite "$prerequisite"; then + failed_prerequisites+=("$prerequisite") + fi + done + if [ ${#failed_prerequisites[@]} -gt 0 ]; then + err "The following prerequisites are missing: ${failed_prerequisites[*]}" + exit 1 + fi +} + +check_prerequisite() { + command -v "$1" &>/dev/null +} + +parse_args() { + while [[ $# -gt 0 ]]; do + case $1 in + --) + shift + break + ;; + -p | --path) + shift + ZKSTACKUP_PATH=$1 + ;; + -l | --local) + ZKSTACKUP_PATH="./" + ;; + -g | --global) + LOCAL_DIR="/usr/local" + BIN_DIR="$LOCAL_DIR/bin" + ;; + -r | --repo) + shift + ZKSTACKUP_REPO=$1 + ;; + -b | --branch) + shift + ZKSTACKUP_BRANCH=$1 + ;; + -c | --commit) + shift + ZKSTACKUP_COMMIT=$1 + ;; + -v | --version) + shift + ZKSTACKUP_VERSION=$1 + ;; + -h | --help) + usage + exit 0 + ;; + *) + err "Unknown argument: $1" + usage + exit 1 + ;; + esac + shift + done +} + +usage() { + cat < Specify a local path to install ZK Stack CLI from. Ignored if --repo is provided. + -l, --local Install ZK Stack CLI from the current directory. Ignored if --repo is provided. + -g, --global Install ZK Stack CLI for all users. + -r, --repo GitHub repository to install from (e.g., "matter-labs/zksync-era"). Defaults to "matter-labs/zksync-era". + -b, --branch Git branch to use when installing from a repository. Ignored if --commit or --version is provided. + -c, --commit Git commit hash to use when installing from a repository. Ignored if --branch or --version is provided. + -v, --version Git tag to use when installing from a repository. Ignored if --branch or --commit is provided. + -h, --help Show this help message and exit. + +Examples: + $(basename "$0") --repo matter-labs/zksync-era --version 0.1.1 +EOF +} + +install_local() { + if [ ! -d "$ZKSTACKUP_PATH/zkstack_cli" ]; then + err "Path $ZKSTACKUP_PATH does not contain zkstack_cli" + exit 1 + fi + + if [ "$ZKSTACKUP_PATH" = "./" ]; then + if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + git config --local core.hooksPath || + git config --local core.hooksPath ./.githooks + fi + fi + + if [ -n "$ZKSTACKUP_BRANCH" ] || [ -n "$ZKSTACKUP_COMMIT" ] || [ -n "$ZKSTACKUP_VERSION" ] || [ -n "$ZKSTACKUP_REPO" ]; then + warn "Ignoring --repo, --branch, --commit and --version arguments when installing from local path" + fi + + say "Installing ZK Stack CLI from $ZKSTACKUP_PATH" + ensure cd "$ZKSTACKUP_PATH"/zkstack_cli + + for bin in "${BINS[@]}"; do + say "Installing $bin" + ensure cargo install --root $LOCAL_DIR --path ./crates/$bin --force + chmod +x "$BIN_DIR/$bin" + done +} + +install_from_repo() { + if [ -n "$ZKSTACKUP_PATH" ]; then + warn "Ignoring --path argument when installing from repository" + fi + + ZKSTACKUP_REPO=${ZKSTACKUP_REPO:-"matter-labs/zksync-era"} + + say "Installing ZK Stack CLI from $ZKSTACKUP_REPO" + + if [ -n "$ZKSTACKUP_VERSION" ]; then + if [ -n "$ZKSTACKUP_COMMIT" ] || [ -n "$ZKSTACKUP_BRANCH" ]; then + warn "Ignoring --commit and --branch arguments when installing by version" + fi + ensure cargo install --root $LOCAL_DIR --git "https://github.com/$ZKSTACKUP_REPO" --tag "zkstack_cli-v$ZKSTACKUP_VERSION" --locked "${BINS[@]}" --force + elif [ -n "$ZKSTACKUP_COMMIT" ]; then + if [ -n "$ZKSTACKUP_BRANCH" ]; then + warn "Ignoring --branch argument when installing by commit" + fi + ensure cargo install --root $LOCAL_DIR --git "https://github.com/$ZKSTACKUP_REPO" --rev "$ZKSTACKUP_COMMIT" --locked "${BINS[@]}" --force + elif [ -n "$ZKSTACKUP_BRANCH" ]; then + ensure cargo install --root $LOCAL_DIR --git "https://github.com/$ZKSTACKUP_REPO" --branch "$ZKSTACKUP_BRANCH" --locked "${BINS[@]}" --force + else + ensure cargo install --root $LOCAL_DIR --git "https://github.com/$ZKSTACKUP_REPO" --locked "${BINS[@]}" --force + fi +} + +add_bin_folder_to_path() { + if [[ ":$PATH:" == *":${BIN_DIR}:"* ]]; then + echo "found ${BIN_DIR} in PATH" + exit 0 + fi + + case $SHELL in + */zsh) + PROFILE="${ZDOTDIR-"$HOME"}/.zshenv" + ;; + */bash) + PROFILE="$HOME/.bashrc" + ;; + */fish) + PROFILE="$HOME/.config/fish/config.fish" + ;; + */ash) + PROFILE="$HOME/.profile" + ;; + *) + echo "could not detect shell, manually add ${BIN_DIR} to your PATH." + exit 1 + ;; + esac + + if [[ ! -f "$PROFILE" ]]; then + echo "Profile file $PROFILE does not exist, creating it." + touch "$PROFILE" + fi + + if [[ "$SHELL" == *"/fish"* ]]; then + echo -e "\n# Added by zkstackup\nfish_add_path -a $BIN_DIR" >>"$PROFILE" + echo "Added $BIN_DIR to PATH in $PROFILE using fish_add_path." + else + echo -e "\n# Added by zkstackup\nexport PATH=\"\$PATH:$BIN_DIR\"" >>"$PROFILE" + echo "Added $BIN_DIR to PATH in $PROFILE." + fi + + echo + echo "Added zkstack to PATH." + echo "Run 'source $PROFILE' or start a new terminal session to use zkstack." +} + +ensure() { + if ! "$@"; then + err "command failed: $*" + exit 1 + fi +} + +say() { + local action="${1%% *}" + local rest="${1#"$action" }" + + echo -e "\033[1;32m$action\033[0m $rest" +} + +success() { + echo -e "\033[1;32m$1\033[0m" +} + +warn() { + echo -e "\033[1;33mWARNING: $1\033[0m" +} + +err() { + echo -e "\033[1;31mERROR: $1\033[0m" >&2 +} + +zkstack_banner() { + printf ' + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + + ███████╗██╗ ██╗ ███████╗████████╗ █████╗ ██████╗██╗ ██╗ + ╚══███╔╝██║ ██╔╝ ██╔════╝╚══██╔══╝██╔══██╗██╔════╝██║ ██╔╝ + ███╔╝ █████╔╝ ███████╗ ██║ ███████║██║ █████╔╝ + ███╔╝ ██╔═██╗ ╚════██║ ██║ ██╔══██║██║ ██╔═██╗ + ███████╗██║ ██╗ ███████║ ██║ ██║ ██║╚██████╗██║ ██╗ + ╚══════╝╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ + + + A Comprehensive Toolkit for Creating and Managing ZK Stack Chains + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +Repo : https://github.com/matter-labs/zksync-era/ +Docs : https://docs.zksync.io/ +Contribute : https://github.com/matter-labs/zksync-era/pulls + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +' +} + +main "$@"