Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: ZK as gateway token #3110

Open
wants to merge 84 commits into
base: sync-layer-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
d1144b5
some changes
kelemeno Sep 2, 2024
368d657
Merge branch 'sync-layer-stable' of github.com:matter-labs/zksync-era…
kelemeno Sep 2, 2024
30508cd
bump contracts
kelemeno Sep 3, 2024
e355e5c
chain.toml
kelemeno Sep 3, 2024
0357fc6
contracts.toml
kelemeno Sep 3, 2024
291972e
bump contracts with fixes
kelemeno Sep 4, 2024
679f8e7
config
kelemeno Sep 4, 2024
01d7391
Merge branch 'sync-layer-stable' of github.com:matter-labs/zksync-era…
kelemeno Sep 11, 2024
db05aba
fixes
kelemeno Sep 12, 2024
b90e9c8
bump contracts
kelemeno Sep 12, 2024
e8775c7
config
kelemeno Sep 12, 2024
644a076
contracts.ts config
kelemeno Sep 13, 2024
bd5ba3d
make CI slightly smaller
kelemeno Sep 13, 2024
886460f
typo
kelemeno Sep 13, 2024
037e7c6
contract env var error
kelemeno Sep 13, 2024
b6f0dfa
config
kelemeno Sep 13, 2024
1b261d9
contracts config
kelemeno Sep 13, 2024
eceb869
config
kelemeno Sep 13, 2024
16fbac8
Merge branch 'sync-layer-stable' of github.com:matter-labs/zksync-era…
kelemeno Sep 13, 2024
6b96da9
chain config
kelemeno Sep 13, 2024
8a06017
config
kelemeno Sep 13, 2024
0efee21
contracts fix
kelemeno Sep 13, 2024
d29dbbd
bump contracts
kelemeno Sep 13, 2024
6dc895f
fixes
kelemeno Sep 14, 2024
c4909f7
bump contracts
kelemeno Sep 14, 2024
2bfc739
contracts config
kelemeno Sep 14, 2024
23c7a87
bump contracts
kelemeno Sep 14, 2024
db612f8
fixed unit tests
kelemeno Sep 16, 2024
a94999d
bump contracts
kelemeno Sep 16, 2024
94edd3c
last test fix
kelemeno Sep 16, 2024
d0bd8a9
fmt
kelemeno Sep 16, 2024
170ae00
l2 native token tests
kelemeno Sep 18, 2024
5983a2e
Merge branch 'sync-layer-stable' of github.com:matter-labs/zksync-era…
kelemeno Sep 18, 2024
3b85806
Merge branch 'sync-layer-stable' of github.com:matter-labs/zksync-era…
kelemeno Sep 26, 2024
16735cf
bump contracts
kelemeno Sep 29, 2024
1ab4295
main gw->L1 migration changes
kelemeno Oct 1, 2024
3eaa189
GW->L1 migration config changes
kelemeno Oct 2, 2024
0ddb00f
Merge branch 'sync-layer-stable' of github.com:matter-labs/zksync-era…
kelemeno Oct 2, 2024
0557dde
fixed most tests
kelemeno Oct 2, 2024
b362e69
Merge branch 'sync-layer-stable' of github.com:matter-labs/zksync-era…
kelemeno Oct 2, 2024
327ee4d
small test fixes
kelemeno Oct 3, 2024
1a0919e
zks fmt
kelemeno Oct 3, 2024
bf85e75
undo test fixes for CI
kelemeno Oct 3, 2024
c4e2e71
comment out l2 tests
kelemeno Oct 3, 2024
12a903e
increase time
kelemeno Oct 3, 2024
affd930
make l2-erc20 test uncommenting work
kelemeno Oct 3, 2024
bfac316
linting
kelemeno Oct 3, 2024
a818916
feat: l2 native contract checks integration tests (#3010)
Raid5594 Oct 3, 2024
c71d11e
bump contracts
kelemeno Oct 3, 2024
fcde977
Merge branch 'sync-layer-stable' of github.com:matter-labs/zksync-era…
kelemeno Oct 3, 2024
0a00512
undo selectors
kelemeno Oct 3, 2024
2565ce7
(test)
Oct 8, 2024
ff3e64c
(feat): ZK token works as gateway base token
Oct 16, 2024
f5120ef
(merge): resolve conflicts
Oct 16, 2024
39d028a
(fix): remove extra wallets in config; add deployer address for base …
Oct 21, 2024
f956fed
(fix): remove unnecessary changes
Oct 21, 2024
15034a1
(fix): one test
Oct 21, 2024
23bbcef
(fix): formatting
Oct 21, 2024
2c109e9
Merge branch 'sync-layer-stable' into ra/zk-as-gateway-token
Raid5594 Oct 21, 2024
7131a38
(update): contracts formatting
Oct 21, 2024
c78124f
(fix): linting, add ZK token to CI
Oct 22, 2024
2481c02
(fix): order of CI actions
Oct 22, 2024
3358ef6
(update): contracts
Oct 22, 2024
ea1553a
(fix): update CI to use netstat instead of lsof
Oct 22, 2024
c9ccf9f
(fix): update scripts
Oct 22, 2024
2f136b8
(fix): distribution amounts
Oct 22, 2024
a4c1d90
(fix): fund chain governance with ZK token
Oct 23, 2024
a5b16d3
(fix): add right contracts commit
Oct 23, 2024
9bf74cc
(fix): switching off era sever test
Oct 23, 2024
a6e3193
(fix): killing the server
Oct 23, 2024
cfd58ef
(test): killing server
Oct 23, 2024
68a805e
(fix): test CI
Oct 23, 2024
fe16190
(fix): test CI
Oct 23, 2024
7364f73
(fix): test CI
Oct 23, 2024
6734edb
(fix): test CI
Oct 23, 2024
bbf7ab2
(fix): test CI
Oct 23, 2024
f924c06
(fix): test CI
Oct 23, 2024
93f461e
(fix): test CI
Oct 23, 2024
e246b1f
(fix): test CI
Oct 23, 2024
b0c0cf4
(fix): wrong place for install of lsof
Oct 23, 2024
b19f17d
(fix): test
Oct 23, 2024
e4d36f8
(fix): add sudo to permit action
Oct 23, 2024
abd6993
(fix): slight refactoring
Oct 25, 2024
7eaf96f
Merge remote-tracking branch 'origin/sync-layer-stable' into ra/zk-as…
Oct 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/scripts/gateway_zktoken.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
sudo rm -rf ./volumes && zk_supervisor clean containers && zk_inception up -o false
Raid5594 marked this conversation as resolved.
Show resolved Hide resolved

zk_inception 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 \
--prover-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--prover-db-name=zksync_prover_localhost_era \
--ignore-prerequisites --observability=false --skip-submodules-checkout \
--chain era \
--verbose

zk_inception server --ignore-prerequisites --chain era &> ./era.log &

sleep 20

zk_inception chain deploy-and-bridge-zk --chain era --verbose

# Define the path to the TOML file
TOML_FILE="contracts/l1-contracts/script-out/output-deploy-zk-token.toml"

# Extract the l1Address from the TOML file
zkL1Address=$(grep -A 1 "\[ZK.l1Address\]" "$TOML_FILE" | grep "l1Address" | awk -F' = ' '{print $2}' | tr -d '"' | tr -d ' ' | tr -d '\n')

# Check if the address starts with 0x and remove it
if [[ $zkL1Address == 0x* ]]; then
zkL1Address="${zkL1Address:2}"
fi

# Output the extracted and sliced l1Address (for debugging purposes)
echo "Sliced l1Address: $zkL1Address"

zk_inception chain create \
--chain-name gateway \
--chain-id 505 \
--prover-mode no-proofs \
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode rollup \
--base-token-address $zkL1Address \
--base-token-price-nominator 1 \
--base-token-price-denominator 1 \
--set-as-default false \
--ignore-prerequisites --skip-submodules-checkout --skip-contract-compilation-override

zk_inception chain init \
--deploy-paymaster \
--l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_gateway \
--prover-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--prover-db-name=zksync_prover_localhost_gateway \
--chain gateway --skip-submodules-checkout

zk_inception chain convert-to-gateway --chain gateway --ignore-prerequisites

SERVER_PID=$(lsof -t -i :3075)

kill -2 $SERVER_PID

zk_inception server --ignore-prerequisites --chain gateway &> ./gateway.log &

sleep 20

zk_inception chain migrate-to-gateway --chain era --gateway-chain-name gateway

zk_inception chain migrate-from-gateway --chain era --gateway-chain-name gateway

zk_inception chain migrate-to-gateway --chain era --gateway-chain-name gateway

zk_inception server --ignore-prerequisites --chain era &> ./rollup.log &

sleep 20

zk_supervisor test integration --no-deps --ignore-prerequisites --chain era
132 changes: 93 additions & 39 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
echo "SCCACHE_GCS_SERVICE_ACCOUNT=gha-ci-runners@matterlabs-infra.iam.gserviceaccount.com" >> .env
echo "SCCACHE_GCS_RW_MODE=READ_WRITE" >> .env
echo "RUSTC_WRAPPER=sccache" >> .env

# TODO: Remove when we after upgrade of hardhat-plugins
- name: pre-download compilers
run: |
Expand Down Expand Up @@ -176,6 +176,10 @@ jobs:
submodules: "recursive"
fetch-depth: 0

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y lsof

- name: Setup environment
run: |
Expand Down Expand Up @@ -234,12 +238,31 @@ jobs:
ci_run git config --global --add safe.directory /usr/src/zksync/contracts

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 \
--ignore-prerequisites --verbose \
--observability=false
--deploy-ecosystem --l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_era \
--ignore-prerequisites --verbose \
--observability=false

- name: Start Era server
run: |
ci_run zkstack server --ignore-prerequisites --chain era &> ${{ env.SERVER_LOGS_DIR }}/rollup.log &

ci_run sleep 20 # Wait for server to start

- name: Deploy and bridge ZK token on Era chain
run: ci_run zk_inception chain deploy-and-bridge-zk --chain era --verbose

- name: Extract ZK token L1 address
run: |
TOML_FILE="contracts/l1-contracts/script-out/output-deploy-zk-token.toml"
zkL1Address=$(grep -A 1 "\[ZK.l1Address\]" "$TOML_FILE" | grep "l1Address" | awk -F' = ' '{print $2}' | tr -d '"' | tr -d ' ' | tr -d '\n')
if [[ $zkL1Address == 0x* ]]; then
zkL1Address="${zkL1Address:2}"
fi
echo "ZK_L1_ADDRESS=$zkL1Address" >> $GITHUB_ENV
echo "Extracted ZK L1 Address: $zkL1Address"

- name: Read Custom Token address and set as environment variable
run: |
CUSTOM_TOKEN_ADDRESS=$(awk -F": " '/tokens:/ {found_tokens=1} found_tokens && /DAI:/ {found_dai=1} found_dai && /address:/ {print $2; exit}' ./configs/erc20.yaml)
Expand Down Expand Up @@ -267,6 +290,8 @@ jobs:
--server-db-name=zksync_server_localhost_validium \
--chain validium

ci_run zk_inception chain deploy-and-bridge-zk --chain era --only-funding-tx --verbose

- name: Create and initialize chain with Custom Token
run: |
ci_run zkstack chain create \
Expand All @@ -288,6 +313,8 @@ jobs:
--server-db-name=zksync_server_localhost_custom_token \
--chain custom_token

ci_run zkstack chain deploy-and-bridge-zk --chain era --only-funding-tx --verbose

# - name: Create and register chain with transactions signed "offline"
# run: |
# ci_run zkstack chain create \
Expand Down Expand Up @@ -323,27 +350,54 @@ jobs:
# exit 1
# fi

- name: Shut down Era server (sends the kill command to all era zksync_server proccesses)
run: |
# Find the PID using ports 3071 or 3075
PIDS=$(sudo lsof -ti :3071 -ti :3075 || true)

# If any PIDs are found, kill them
if [ -n "$PIDS" ]; then
echo "Killing process(es) on ports 3071 or 3075 with PID(s): $PIDS"
for PID in $PIDS; do
# Attempt graceful shutdown
sudo kill -2 "$PID" || true
sleep 10

# Check if still running, then force kill
if sudo kill -0 "$PID" 2>/dev/null; then
echo "Process $PID still running, forcing termination."
sudo kill -9 "$PID" || true
fi
# sudo kill -9 "$PID" || true # Use SIGKILL to ensure termination
done
else
echo "No processes found on ports 3071 or 3075."
fi

# Ensure the script always exits successfully
exit 0

- name: Create and initialize Consensus chain
run: |
ci_run zkstack chain create \
--chain-name consensus \
--chain-id sequential \
--prover-mode no-proofs \
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode validium \
--base-token-address ${{ env.CUSTOM_TOKEN_ADDRESS }} \
--base-token-price-nominator 3 \
--base-token-price-denominator 2 \
--set-as-default false \
--ignore-prerequisites
--chain-name consensus \
--chain-id sequential \
--prover-mode no-proofs \
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode validium \
--base-token-address ${{ env.CUSTOM_TOKEN_ADDRESS }} \
--base-token-price-nominator 3 \
--base-token-price-denominator 2 \
--set-as-default false \
--ignore-prerequisites

ci_run zkstack chain init \
--deploy-paymaster \
--l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_consensus \
--chain consensus

--deploy-paymaster \
--l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_consensus \
--chain consensus
- name: Export chain list to environment variable
run: |
CHAINS="era,validium,custom_token,consensus"
Expand All @@ -352,24 +406,24 @@ jobs:
- name: Initialize gateway chain
run: |
ci_run zkstack chain create \
--chain-name gateway \
--chain-id 505 \
--prover-mode no-proofs \
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode rollup \
--base-token-address 0x0000000000000000000000000000000000000001 \
--base-token-price-nominator 1 \
--base-token-price-denominator 1 \
--set-as-default false \
--ignore-prerequisites
--chain-name gateway \
--chain-id 505 \
--prover-mode no-proofs \
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode rollup \
--base-token-address ${{ env.ZK_L1_ADDRESS }} \
--base-token-price-nominator 1 \
--base-token-price-denominator 1 \
--set-as-default false \
--ignore-prerequisites

ci_run zkstack chain init \
--deploy-paymaster \
--l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_gateway \
--chain gateway
--deploy-paymaster \
--l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_gateway \
--chain gateway

ci_run zkstack chain convert-to-gateway --chain gateway --ignore-prerequisites

- name: Run gateway
Expand Down
4 changes: 2 additions & 2 deletions etc/env/file_based/genesis.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
genesis_root: 0x526a5d3e384ff95a976283c79a976e0a2fb749e4631233f29d3765201efd937d
genesis_batch_commitment: 0xb9794246425fd654cf6a4c2e9adfdd48aaaf97bf3b8ba6bdc88e1d141bcfa5b3
genesis_root: 0x59907f1d1a7d24b6d93f4654e413309e6cb58c8f01c141ee5941dba2270e8303
genesis_batch_commitment: 0x7484436f4406a9b6d2966dab11c0f15b0b27d087f447519492829a5587be3ed7
genesis_rollup_leaf_index: 64
default_aa_hash: 0x0100055d3993e14104994ca4d8cfa91beb9b544ee86894b45708b4824d832ff2
bootloader_hash: 0x010008c753336bc8d1ddca235602b9f31d346412b2d463cd342899f7bfb73baf
Expand Down
11 changes: 8 additions & 3 deletions zkstack_cli/crates/common/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ abigen!(
function symbol() external view returns (string)
function decimals() external view returns (uint8)
function mint(address to, uint256 amount)
function transfer(address to, uint256 amount)
]"
);

Expand Down Expand Up @@ -96,17 +97,21 @@ pub async fn mint_token(
let contract = TokenContract::new(token_address, client);

let mut pending_calls = vec![];
for address in addresses {
let mut pending_txs = vec![];
for address in addresses.clone() {
pending_calls.push(contract.mint(address, amount.into()));
}

let mut pending_txs = vec![];
for address in addresses {
pending_calls.push(contract.transfer(address, amount.into()));
}

for call in &pending_calls {
let call = call.send().await;
match call {
// It's safe to set such low number of confirmations and low interval for localhost
Ok(call) => pending_txs.push(call.confirmations(3).interval(Duration::from_millis(30))),
Err(e) => logger::error(format!("Minting is not successful {e}")),
Err(e) => logger::error(format!("Minting or transfer is not successful {e}")),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ impl Default for Erc20DeploymentConfig {
implementation: String::from("TestnetERC20Token.sol"),
mint: U256::from_str("9000000000000000000000").unwrap(),
},
Erc20DeploymentTokensConfig {
name: String::from("ZK"),
symbol: String::from("ZK"),
decimals: 8,
implementation: String::from("TestnetERC20Token.sol"),
mint: U256::from_str("9000000000000000000000").unwrap(),
},
],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ pub const GATEWAY_PREPARATION: ForgeScriptParams = ForgeScriptParams {
output: "script-out/output-gateway-preparation-l1.toml",
script_path: "deploy-scripts/GatewayPreparation.s.sol",
};

pub const ZK_PREPARATION: ForgeScriptParams = ForgeScriptParams {
input: "script-config/config-deploy-zk.toml",
output: "script-out/output-deploy-zk-token.toml",
script_path: "deploy-scripts/DeployZKAndBridgeToL1.s.sol",
};
8 changes: 7 additions & 1 deletion zkstack_cli/crates/zkstack/src/commands/chain/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ pub async fn mint_base_token(
let wallets = ecosystem_config.get_wallets()?;
let chain_wallets = chain_config.get_wallets_config()?;
let base_token = &chain_config.base_token;
let addresses = vec![wallets.governor.address, chain_wallets.governor.address];
let addresses = vec![
wallets.governor.address,
wallets.deployer.unwrap().address,
chain_wallets.governor.address,
chain_wallets.deployer.unwrap().address,
];

let amount = AMOUNT_FOR_DISTRIBUTION_TO_WALLETS * base_token.nominator as u128
/ base_token.denominator as u128;
common::ethereum::mint_token(
Expand Down
Loading
Loading