Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into add-pairing-precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchatruc committed Apr 23, 2024
2 parents c2edbbb + 597280b commit d7112b5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 9 deletions.
6 changes: 6 additions & 0 deletions core/lib/constants/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ pub const CODE_ORACLE_ADDRESS: Address = H160([
0x00, 0x00, 0x80, 0x12,
]);

/// Note, that the `Create2Factory` is explicitly deployed on a non-system-contract address.
pub const CREATE2_FACTORY_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00,
]);

pub const ERC20_TRANSFER_TOPIC: H256 = H256([
221, 242, 82, 173, 27, 226, 200, 155, 105, 194, 176, 104, 252, 55, 141, 170, 149, 43, 167, 241,
99, 196, 161, 22, 40, 245, 90, 77, 245, 35, 179, 239,
Expand Down
12 changes: 9 additions & 3 deletions core/lib/types/src/system_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use once_cell::sync::Lazy;
use zksync_basic_types::{AccountTreeId, Address, U256};
use zksync_contracts::{read_sys_contract_bytecode, ContractLanguage, SystemContractsRepo};
use zksync_system_constants::{
BOOTLOADER_UTILITIES_ADDRESS, CODE_ORACLE_ADDRESS, COMPRESSOR_ADDRESS, EVENT_WRITER_ADDRESS,
P256VERIFY_PRECOMPILE_ADDRESS, PUBDATA_CHUNK_PUBLISHER_ADDRESS,
BOOTLOADER_UTILITIES_ADDRESS, CODE_ORACLE_ADDRESS, COMPRESSOR_ADDRESS, CREATE2_FACTORY_ADDRESS,
EVENT_WRITER_ADDRESS, P256VERIFY_PRECOMPILE_ADDRESS, PUBDATA_CHUNK_PUBLISHER_ADDRESS,
};

use crate::{
Expand All @@ -25,7 +25,7 @@ use crate::{
pub const TX_NONCE_INCREMENT: U256 = U256([1, 0, 0, 0]); // 1
pub const DEPLOYMENT_NONCE_INCREMENT: U256 = U256([0, 0, 1, 0]); // 2^128

static SYSTEM_CONTRACT_LIST: [(&str, &str, Address, ContractLanguage); 24] = [
static SYSTEM_CONTRACT_LIST: [(&str, &str, Address, ContractLanguage); 25] = [
(
"",
"AccountCodeStorage",
Expand Down Expand Up @@ -162,6 +162,12 @@ static SYSTEM_CONTRACT_LIST: [(&str, &str, Address, ContractLanguage); 24] = [
PUBDATA_CHUNK_PUBLISHER_ADDRESS,
ContractLanguage::Sol,
),
(
"",
"Create2Factory",
CREATE2_FACTORY_ADDRESS,
ContractLanguage::Sol,
),
];

static SYSTEM_CONTRACTS: Lazy<Vec<DeployedContract>> = Lazy::new(|| {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import {IContractDeployer} from "./IContractDeployer.sol";

/// @custom:security-contact [email protected]
/// @author Matter Labs
/// @notice The interface for the contract that can be used for deterministic contract deployment.
interface ICreate2Factory {
/// @notice Function that calls the `create2` method of the `ContractDeployer` contract.
/// @dev This function accepts the same parameters as the `create2` function of the ContractDeployer system contract,
/// so that we could efficiently relay the calldata.
function create2(
bytes32 _salt,
bytes32 _bytecodeHash,
bytes calldata _input
) external payable returns (address);

/// @notice Function that calls the `create2Account` method of the `ContractDeployer` contract.
/// @dev This function accepts the same parameters as the `create2Account` function of the ContractDeployer system contract,
/// so that we could efficiently relay the calldata.
function create2Account(
bytes32 _salt,
bytes32 _bytecodeHash,
bytes calldata _input,
IContractDeployer.AccountAbstractionVersion
) external payable returns (address);
}
23 changes: 23 additions & 0 deletions core/tests/ts-integration/tests/system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const contracts = {
events: getTestContract('Emitter')
};

const BUILTIN_CREATE2_FACTORY_ADDRESS = '0x0000000000000000000000000000000000010000';

describe('System behavior checks', () => {
let testMaster: TestMaster;
let alice: zksync.Wallet;
Expand Down Expand Up @@ -315,6 +317,27 @@ describe('System behavior checks', () => {
).toBeRejected('exceeds block gas limit');
});

it('Create2Factory should work', async () => {
// For simplicity, we'll just deploy a contract factory
const salt = ethers.utils.randomBytes(32);

const bytecode = await alice.provider.getCode(BUILTIN_CREATE2_FACTORY_ADDRESS);
const abi = getTestContract('ICreate2Factory').abi;
const hash = hashBytecode(bytecode);

const contractFactory = new ethers.Contract(BUILTIN_CREATE2_FACTORY_ADDRESS, abi, alice);

const deploymentTx = await (await contractFactory.create2(salt, hash, [])).wait();

const deployedAddresses = zksync.utils.getDeployedContracts(deploymentTx);
expect(deployedAddresses.length).toEqual(1);
const deployedAddress = deployedAddresses[0];
const correctCreate2Address = zksync.utils.create2Address(contractFactory.address, hash, salt, []);

expect(deployedAddress.deployedAddress.toLocaleLowerCase()).toEqual(correctCreate2Address.toLocaleLowerCase());
expect(await alice.provider.getCode(deployedAddress.deployedAddress)).toEqual(bytecode);
});

afterAll(async () => {
await testMaster.deinitialize();
});
Expand Down
5 changes: 2 additions & 3 deletions docker/external-node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ FROM matterlabs/zksync-build-base:latest as builder

WORKDIR /usr/src/zksync
COPY . .

RUN cargo build --release --features=rocksdb/io-uring
RUN cargo build --release

FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y curl libpq5 ca-certificates liburing-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y curl libpq5 ca-certificates && rm -rf /var/lib/apt/lists/*

COPY --from=builder /usr/src/zksync/target/release/zksync_external_node /usr/bin
COPY --from=builder /usr/src/zksync/target/release/block_reverter /usr/bin
Expand Down
6 changes: 3 additions & 3 deletions etc/env/base/contracts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ RECURSION_NODE_LEVEL_VK_HASH = "0x1186ec268d49f1905f8d9c1e9d39fc33e98c74f91d91a2
RECURSION_LEAF_LEVEL_VK_HASH = "0x101e08b00193e529145ee09823378ef51a3bc8966504064f1f6ba3f1ba863210"
RECURSION_CIRCUITS_SET_VKS_HASH = "0x18c1639094f58177409186e8c48d9f577c9410901d2f1d486b3e7d6cf553ae4c"
GENESIS_TX_HASH = "0xb99ebfea46cbe05a21cd80fe5597d97b204befc52a16303f579c607dc1ac2e2e"
GENESIS_ROOT = "0x907bb6f50dfd40bfcc07cbe926a7c5bd233beed98cbb07fe744f84547a1b54b6"
GENESIS_BATCH_COMMITMENT = "0xd5b4bd7de59bdc30b4bf6a85701f183599dc4e09eb7805e4a7b4d29b9c29e7cd"
GENESIS_ROOT = "0xabdb766b18a479a5c783a4b80e12686bc8ea3cc2d8a3050491b701d72370ebb5"
GENESIS_BATCH_COMMITMENT = "0x49276362411c40c07ab01d3dfa9428abca95e361d8c980cd39f1ab6a9c561c0c"
PRIORITY_TX_MAX_GAS_LIMIT = 72000000
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT = 10000000
GENESIS_ROLLUP_LEAF_INDEX = "52"
GENESIS_ROLLUP_LEAF_INDEX = "54"
GENESIS_PROTOCOL_VERSION = "23"
L1_WETH_BRIDGE_IMPL_ADDR = "0x5E6D086F5eC079ADFF4FB3774CDf3e8D6a34F7E9"
L1_WETH_BRIDGE_PROXY_ADDR = "0x5E6D086F5eC079ADFF4FB3774CDf3e8D6a34F7E9"
Expand Down

0 comments on commit d7112b5

Please sign in to comment.