Skip to content

Commit

Permalink
feat: l2 native token tests (#2916)
Browse files Browse the repository at this point in the history
## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] 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 fmt` and `zk lint`.

---------

Co-authored-by: Raid5594 <[email protected]>
Co-authored-by: Raid Ateir <[email protected]>
  • Loading branch information
3 people authored Oct 8, 2024
1 parent 8f43a5f commit dfe03d3
Show file tree
Hide file tree
Showing 40 changed files with 918 additions and 47 deletions.
50 changes: 50 additions & 0 deletions .github/scripts/gateway.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
sudo rm -rf ./volumes && zk_supervisor clean containers && zk_inception up -o false

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 \
# --skip-contract-compilation-override \

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 0x0000000000000000000000000000000000000001 \
--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

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
8 changes: 8 additions & 0 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ jobs:
ci_run zk_inception chain migrate-to-gateway --chain era --gateway-chain-name gateway
ci_run zk_inception chain migrate-to-gateway --chain validium --gateway-chain-name gateway
ci_run zk_inception chain migrate-to-gateway --chain custom_token --gateway-chain-name gateway
- name: Migrate back era
run: |
ci_run zk_inception chain migrate-from-gateway --chain era --gateway-chain-name gateway
- name: Migrate to gateway again
run: |
ci_run zk_inception chain migrate-to-gateway --chain era --gateway-chain-name gateway
- name: Build test dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion contracts
Submodule contracts updated 58 files
+1 −0 l1-contracts/.env
+15 −1 l1-contracts/contracts/bridge/BridgedStandardERC20.sol
+9 −6 l1-contracts/contracts/bridge/L1Nullifier.sol
+2 −2 l1-contracts/contracts/bridge/L2SharedBridgeLegacy.sol
+18 −1 l1-contracts/contracts/bridge/L2WrappedBaseToken.sol
+6 −0 l1-contracts/contracts/bridge/asset-router/AssetRouterBase.sol
+29 −0 l1-contracts/contracts/bridge/asset-router/IL1AssetRouter.sol
+4 −2 l1-contracts/contracts/bridge/asset-router/IL2AssetRouter.sol
+41 −5 l1-contracts/contracts/bridge/asset-router/L1AssetRouter.sol
+32 −11 l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol
+4 −0 l1-contracts/contracts/bridge/interfaces/IBridgedStandardToken.sol
+1 −1 l1-contracts/contracts/bridge/interfaces/IL2SharedBridgeLegacy.sol
+10 −2 l1-contracts/contracts/bridge/ntv/INativeTokenVault.sol
+29 −2 l1-contracts/contracts/bridge/ntv/L1NativeTokenVault.sol
+7 −5 l1-contracts/contracts/bridge/ntv/L2NativeTokenVault.sol
+31 −14 l1-contracts/contracts/bridge/ntv/NativeTokenVault.sol
+10 −4 l1-contracts/contracts/bridgehub/Bridgehub.sol
+1 −1 l1-contracts/contracts/bridgehub/CTMDeploymentTracker.sol
+1 −1 l1-contracts/contracts/bridgehub/IBridgehub.sol
+1 −1 l1-contracts/contracts/bridgehub/ICTMDeploymentTracker.sol
+5 −0 l1-contracts/contracts/common/Config.sol
+19 −12 l1-contracts/contracts/common/L1ContractErrors.sol
+78 −0 l1-contracts/contracts/dev-contracts/test/L2NativeTokenVaultDev.sol
+3 −0 l1-contracts/contracts/state-transition/chain-interfaces/IAdmin.sol
+67 −487 l1-contracts/deploy-scripts/DeployL1.s.sol
+483 −0 l1-contracts/deploy-scripts/DeployUtils.s.sol
+102 −18 l1-contracts/deploy-scripts/GatewayPreparation.s.sol
+30 −26 l1-contracts/deploy-scripts/RegisterZKChain.s.sol
+1 −1 l1-contracts/package.json
+3 −1 l1-contracts/src.ts/deploy.ts
+11 −3 l1-contracts/test/foundry/l1/integration/AssetRouterTest.t.sol
+5 −5 l1-contracts/test/foundry/l1/integration/BridgeHubInvariantTests.t.sol
+5 −5 l1-contracts/test/foundry/l1/integration/BridgehubTests.t.sol
+65 −6 l1-contracts/test/foundry/l1/integration/DeploymentTest.t.sol
+97 −107 l1-contracts/test/foundry/l1/integration/L1GatewayTests.t.sol
+3 −2 l1-contracts/test/foundry/l1/integration/_GatewayPreparationForTests.sol
+3 −3 l1-contracts/test/foundry/l1/integration/_SharedGatewayDeployer.t.sol
+25 −18 l1-contracts/test/foundry/l1/integration/_SharedL1ContractDeployer.t.sol
+11 −6 l1-contracts/test/foundry/l1/integration/_SharedZKChainDeployer.t.sol
+1 −1 l1-contracts/test/foundry/l1/integration/deploy-scripts/script-config/config-deploy-l1.toml
+51 −0 l1-contracts/test/foundry/l1/integration/l2-tests-in-l1-context/L2Erc20L1Test.t.sol
+16 −54 l1-contracts/test/foundry/l1/integration/l2-tests-in-l1-context/L2Erc20TestAbstract.t.sol
+51 −0 l1-contracts/test/foundry/l1/integration/l2-tests-in-l1-context/L2GatewayL1Test.t.sol
+85 −0 l1-contracts/test/foundry/l1/integration/l2-tests-in-l1-context/L2GatewayTestAbstract.t.sol
+25 −20 l1-contracts/test/foundry/l1/integration/l2-tests-in-l1-context/L2WethTestAbstract.t.sol
+202 −0 l1-contracts/test/foundry/l1/integration/l2-tests-in-l1-context/_SharedL2ContractDeployer.sol
+129 −0 l1-contracts/test/foundry/l1/integration/l2-tests-in-l1-context/_SharedL2ContractL1DeployerUtils.sol
+0 −5 l1-contracts/test/foundry/l1/unit/concrete/Bridges/L1SharedBridge/_L1SharedBridge_Shared.t.sol
+49 −0 l1-contracts/test/foundry/l2/integration/L2ERC20BridgeTest.t.sol
+60 −0 l1-contracts/test/foundry/l2/integration/L2GatewayTests.t.sol
+114 −45 l1-contracts/test/foundry/l2/integration/L2Utils.sol
+36 −0 l1-contracts/test/foundry/l2/integration/WETH.t.sol
+41 −0 l1-contracts/test/foundry/l2/integration/_SharedL2ContractL2DeployerUtils.sol
+1 −1 l2-contracts/test/foundry/unit/data-availability/ValidiumL2DAValidator.t.sol
+11 −11 system-contracts/SystemContractsHashes.json
+2 −2 system-contracts/contracts/L2GatewayUpgrade.sol
+2 −2 system-contracts/contracts/L2GenesisUpgrade.sol
+2 −2 system-contracts/contracts/L2GenesisUpgradeHelper.sol
3 changes: 3 additions & 0 deletions core/lib/config/src/configs/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct ContractsConfig {
pub l2_da_validator_addr: Option<Address>,

pub chain_admin_addr: Option<Address>,

pub settlement_layer: Option<u64>,
}

impl ContractsConfig {
Expand All @@ -78,6 +80,7 @@ impl ContractsConfig {
user_facing_diamond_proxy_addr: Some(Address::repeat_byte(0x16)),
chain_admin_addr: Some(Address::repeat_byte(0x18)),
l2_da_validator_addr: Some(Address::repeat_byte(0x19)),
settlement_layer: Some(0),
}
}
}
4 changes: 4 additions & 0 deletions core/lib/config/src/configs/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ pub struct GatewayChainConfig {
pub diamond_proxy_addr: Address,
pub chain_admin_addr: Option<Address>,
pub governance_addr: Address,
pub settlement_layer: u64,
}

impl GatewayChainConfig {
pub fn from_gateway_and_chain_data(
gateway_config: &GatewayConfig,
diamond_proxy_addr: Address,
chain_admin_addr: Address,
settlement_layer: u64,
) -> Self {
// FIXME: there is no "governnace" for a chain, only an admin, we
// need to figure out what we mean here
Expand All @@ -48,6 +50,7 @@ impl GatewayChainConfig {
diamond_proxy_addr,
chain_admin_addr: Some(chain_admin_addr),
governance_addr: chain_admin_addr,
settlement_layer,
}
}
}
Expand All @@ -64,6 +67,7 @@ impl From<ContractsConfig> for GatewayChainConfig {
diamond_proxy_addr: value.diamond_proxy_addr,
chain_admin_addr: value.chain_admin_addr,
governance_addr: value.governance_addr,
settlement_layer: value.settlement_layer.unwrap(),
}
}
}
1 change: 1 addition & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ impl Distribution<configs::ContractsConfig> for EncodeDist {
l2_da_validator_addr: rng.gen(),
base_token_addr: self.sample_opt(|| rng.gen()),
chain_admin_addr: self.sample_opt(|| rng.gen()),
settlement_layer: self.sample_opt(|| rng.gen()),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/lib/env_config/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ mod tests {
)),
chain_admin_addr: Some(addr("0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347ff")),
l2_da_validator_addr: Some(addr("0xed6fa5c14e7550b4caf2aa2818d24c69cbc347ff")),
settlement_layer: Some(0),
}
}

Expand Down Expand Up @@ -129,6 +130,7 @@ CONTRACTS_USER_FACING_DIAMOND_PROXY_ADDR="0xF00B988a98Ca742e7958DeF9F7823b590871
CONTRACTS_L2_NATIVE_TOKEN_VAULT_PROXY_ADDR="0xfc073319977e314f251eae6ae6be76b0b3baeecf"
CONTRACTS_L2_DA_VALIDATOR_ADDR="0xed6fa5c14e7550b4caf2aa2818d24c69cbc347ff"
CONTRACTS_CHAIN_ADMIN_ADDR="0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347ff"
CONTRACTS_SETTLEMENT_LAYER="0"
"#;
lock.set_env(config);

Expand Down
2 changes: 2 additions & 0 deletions core/lib/protobuf_config/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl ProtoRepr for proto::Contracts {
.map(|x| parse_h160(x))
.transpose()
.context("chain_admin_addr")?,
settlement_layer: self.settlement_layer,
})
}

Expand Down Expand Up @@ -191,6 +192,7 @@ impl ProtoRepr for proto::Contracts {
user_facing_diamond_proxy: this
.user_facing_diamond_proxy_addr
.map(|a| format!("{:?}", a)),
settlement_layer: this.settlement_layer,
}
}
}
2 changes: 2 additions & 0 deletions core/lib/protobuf_config/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl ProtoRepr for proto::GatewayChainConfig {
governance_addr: required(&self.governance_addr)
.and_then(|x| parse_h160(x))
.context("governance_addr")?,
settlement_layer: *required(&self.settlement_layer)?,
})
}

Expand All @@ -45,6 +46,7 @@ impl ProtoRepr for proto::GatewayChainConfig {
diamond_proxy_addr: Some(format!("{:?}", this.diamond_proxy_addr)),
chain_admin_addr: this.chain_admin_addr.map(|x| format!("{:?}", x)),
governance_addr: Some(format!("{:?}", this.governance_addr)),
settlement_layer: Some(this.settlement_layer),
}
}
}
1 change: 1 addition & 0 deletions core/lib/protobuf_config/src/proto/config/contracts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ message Contracts {
optional EcosystemContracts ecosystem_contracts = 4;
optional string user_facing_bridgehub = 5;
optional string user_facing_diamond_proxy = 6;
optional uint64 settlement_layer = 7;
}
1 change: 1 addition & 0 deletions core/lib/protobuf_config/src/proto/config/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ message GatewayChainConfig {
optional string diamond_proxy_addr = 4;
optional string chain_admin_addr = 5;
optional string governance_addr = 6;
optional uint64 settlement_layer = 7;
}
1 change: 0 additions & 1 deletion core/node/api_server/src/web3/namespaces/zks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,6 @@ impl ZksNamespace {
batch_number: L1BatchNumber,
) -> Result<Option<L1ProcessingDetails>, Web3Error> {
let mut storage = self.state.acquire_connection().await?;
println!("\n\nHey1\n\n");
self.state
.start_info
.ensure_not_pruned(batch_number, &mut storage)
Expand Down
15 changes: 8 additions & 7 deletions core/node/genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ impl GenesisParams {
) -> Result<GenesisParams, GenesisError> {
println!(
"
bootloader_hash = \"{:?}\"
default_aa_hash = \"{:?}\"
GENESIS_PROTOCOL_SEMANTIC_VERSION = \"{:?}\"
bootloader_hash: {:?}
default_aa_hash: {:?}
genesis_protocol_semantic_version: 0.{:?}.{:?}
",
base_system_contracts.hashes().bootloader,
base_system_contracts.hashes().default_aa,
config.protocol_version.unwrap(),
config.protocol_version.unwrap().minor,
config.protocol_version.unwrap().patch,
);
let base_system_contracts_hashes = BaseSystemContractsHashes {
bootloader: config
Expand Down Expand Up @@ -339,9 +340,9 @@ pub async fn ensure_genesis_state(
} = insert_genesis_batch(&mut transaction, genesis_params).await?;
println!(
"
GENESIS_ROOT = \"{:?}\"
GENESIS_BATCH_COMMITMENT = \"{:?}\"
GENESIS_ROLLUP_LEAF_INDEX = \"{:?}\"
genesis_root: {:?}
genesis_batch_commitment: {:?}
genesis_rollup_leaf_index: {:?}
",
root_hash, commitment, rollup_last_leaf_index
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,26 @@ impl WiringLayer for PKSigningEthClientLayer {
BoundEthInterfaceForBlobsResource(Box::new(signing_client_for_blobs))
});
let signing_client_for_gateway = if input.gateway_client.is_some() {
let private_key = self.wallets.operator.private_key();
let GatewayEthInterfaceResource(gateway_client) = input.gateway_client.unwrap();
let signing_client_for_blobs = PKSigningClient::new_raw(
private_key.clone(),
self.gateway_contracts_config.unwrap().diamond_proxy_addr,
gas_adjuster_config.default_priority_fee_per_gas,
self.sl_chain_id,
gateway_client,
);
Some(BoundEthInterfaceForL2Resource(Box::new(
signing_client_for_blobs,
)))
if self
.gateway_contracts_config
.clone()
.is_some_and(|v| v.settlement_layer != 0_u64)
{
let private_key = self.wallets.operator.private_key();
let GatewayEthInterfaceResource(gateway_client) = input.gateway_client.unwrap();
let signing_client_for_blobs = PKSigningClient::new_raw(
private_key.clone(),
self.gateway_contracts_config.unwrap().diamond_proxy_addr,
gas_adjuster_config.default_priority_fee_per_gas,
self.sl_chain_id,
gateway_client,
);
Some(BoundEthInterfaceForL2Resource(Box::new(
signing_client_for_blobs,
)))
} else {
None
}
} else {
None
};
Expand Down
3 changes: 2 additions & 1 deletion core/tests/ts-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"ts-jest": "^29.0.1",
"ts-node": "^10.1.0",
"typescript": "^4.3.5",
"zksync-ethers": "^6.9.0",
"zksync-ethers": "git+https://github.com/zksync-sdk/zksync-ethers#ra/fix-l2-l1-bridging",
"zksync-ethers-gw": "https://github.com/zksync-sdk/zksync-ethers#kl/gateway-support",
"elliptic": "^6.5.5",
"yaml": "^2.4.2"
}
Expand Down
4 changes: 4 additions & 0 deletions core/tests/ts-integration/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export function getContractSource(relativePath: string): string {
return source;
}

export function readContract(path: string, fileName: string) {
return JSON.parse(fs.readFileSync(`${path}/${fileName}.sol/${fileName}.json`, { encoding: 'utf-8' }));
}

/**
* Performs a contract deployment
*
Expand Down
2 changes: 1 addition & 1 deletion core/tests/ts-integration/tests/contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Smart contract behavior checks', () => {

// We manually provide a constant, since otherwise the exception would be thrown
// while estimating gas
await expect(counterContract.incrementWithRevert(5, true, { gasLimit: 5000000, gasPrice })).toBeReverted([]);
await expect(counterContract.incrementWithRevert(5, true, { gasLimit: 5000000, gasPrice })).toBeReverted();

// The tx has been reverted, so the value Should not have been changed:
const newValue = await counterContract.get();
Expand Down
2 changes: 1 addition & 1 deletion core/tests/ts-integration/tests/erc20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as ethers from 'ethers';
import { scaledGasPrice, waitForBlockToBeFinalizedOnL1 } from '../src/helpers';
import { L2_DEFAULT_ETH_PER_ACCOUNT } from '../src/context-owner';

describe('ERC20 contract checks', () => {
describe('L1 ERC20 contract checks', () => {
let testMaster: TestMaster;
let alice: zksync.Wallet;
let bob: zksync.Wallet;
Expand Down
Loading

0 comments on commit dfe03d3

Please sign in to comment.