Skip to content

Commit 597280b

Browse files
feat: Include create2 factory in genesis (matter-labs#1775)
## 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`. - [ ] Spellcheck has been run via `zk spellcheck`. - [ ] Linkcheck has been run via `zk linkcheck`.
1 parent 1c02ec6 commit 597280b

File tree

5 files changed

+70
-6
lines changed

5 files changed

+70
-6
lines changed

core/lib/constants/src/contracts.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ pub const CODE_ORACLE_ADDRESS: Address = H160([
120120
0x00, 0x00, 0x80, 0x12,
121121
]);
122122

123+
/// Note, that the `Create2Factory` is explicitly deployed on a non-system-contract address.
124+
pub const CREATE2_FACTORY_ADDRESS: Address = H160([
125+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126+
0x00, 0x01, 0x00, 0x00,
127+
]);
128+
123129
pub const ERC20_TRANSFER_TOPIC: H256 = H256([
124130
221, 242, 82, 173, 27, 226, 200, 155, 105, 194, 176, 104, 252, 55, 141, 170, 149, 43, 167, 241,
125131
99, 196, 161, 22, 40, 245, 90, 77, 245, 35, 179, 239,

core/lib/types/src/system_contracts.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use once_cell::sync::Lazy;
44
use zksync_basic_types::{AccountTreeId, Address, U256};
55
use zksync_contracts::{read_sys_contract_bytecode, ContractLanguage, SystemContractsRepo};
66
use zksync_system_constants::{
7-
BOOTLOADER_UTILITIES_ADDRESS, CODE_ORACLE_ADDRESS, COMPRESSOR_ADDRESS, EVENT_WRITER_ADDRESS,
8-
P256VERIFY_PRECOMPILE_ADDRESS, PUBDATA_CHUNK_PUBLISHER_ADDRESS,
7+
BOOTLOADER_UTILITIES_ADDRESS, CODE_ORACLE_ADDRESS, COMPRESSOR_ADDRESS, CREATE2_FACTORY_ADDRESS,
8+
EVENT_WRITER_ADDRESS, P256VERIFY_PRECOMPILE_ADDRESS, PUBDATA_CHUNK_PUBLISHER_ADDRESS,
99
};
1010

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

28-
static SYSTEM_CONTRACT_LIST: [(&str, &str, Address, ContractLanguage); 23] = [
28+
static SYSTEM_CONTRACT_LIST: [(&str, &str, Address, ContractLanguage); 24] = [
2929
(
3030
"",
3131
"AccountCodeStorage",
@@ -156,6 +156,12 @@ static SYSTEM_CONTRACT_LIST: [(&str, &str, Address, ContractLanguage); 23] = [
156156
PUBDATA_CHUNK_PUBLISHER_ADDRESS,
157157
ContractLanguage::Sol,
158158
),
159+
(
160+
"",
161+
"Create2Factory",
162+
CREATE2_FACTORY_ADDRESS,
163+
ContractLanguage::Sol,
164+
),
159165
];
160166

161167
static SYSTEM_CONTRACTS: Lazy<Vec<DeployedContract>> = Lazy::new(|| {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import {IContractDeployer} from "./IContractDeployer.sol";
6+
7+
/// @custom:security-contact [email protected]
8+
/// @author Matter Labs
9+
/// @notice The interface for the contract that can be used for deterministic contract deployment.
10+
interface ICreate2Factory {
11+
/// @notice Function that calls the `create2` method of the `ContractDeployer` contract.
12+
/// @dev This function accepts the same parameters as the `create2` function of the ContractDeployer system contract,
13+
/// so that we could efficiently relay the calldata.
14+
function create2(
15+
bytes32 _salt,
16+
bytes32 _bytecodeHash,
17+
bytes calldata _input
18+
) external payable returns (address);
19+
20+
/// @notice Function that calls the `create2Account` method of the `ContractDeployer` contract.
21+
/// @dev This function accepts the same parameters as the `create2Account` function of the ContractDeployer system contract,
22+
/// so that we could efficiently relay the calldata.
23+
function create2Account(
24+
bytes32 _salt,
25+
bytes32 _bytecodeHash,
26+
bytes calldata _input,
27+
IContractDeployer.AccountAbstractionVersion
28+
) external payable returns (address);
29+
}

core/tests/ts-integration/tests/system.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const contracts = {
2020
events: getTestContract('Emitter')
2121
};
2222

23+
const BUILTIN_CREATE2_FACTORY_ADDRESS = '0x0000000000000000000000000000000000010000';
24+
2325
describe('System behavior checks', () => {
2426
let testMaster: TestMaster;
2527
let alice: zksync.Wallet;
@@ -315,6 +317,27 @@ describe('System behavior checks', () => {
315317
).toBeRejected('exceeds block gas limit');
316318
});
317319

320+
it('Create2Factory should work', async () => {
321+
// For simplicity, we'll just deploy a contract factory
322+
const salt = ethers.utils.randomBytes(32);
323+
324+
const bytecode = await alice.provider.getCode(BUILTIN_CREATE2_FACTORY_ADDRESS);
325+
const abi = getTestContract('ICreate2Factory').abi;
326+
const hash = hashBytecode(bytecode);
327+
328+
const contractFactory = new ethers.Contract(BUILTIN_CREATE2_FACTORY_ADDRESS, abi, alice);
329+
330+
const deploymentTx = await (await contractFactory.create2(salt, hash, [])).wait();
331+
332+
const deployedAddresses = zksync.utils.getDeployedContracts(deploymentTx);
333+
expect(deployedAddresses.length).toEqual(1);
334+
const deployedAddress = deployedAddresses[0];
335+
const correctCreate2Address = zksync.utils.create2Address(contractFactory.address, hash, salt, []);
336+
337+
expect(deployedAddress.deployedAddress.toLocaleLowerCase()).toEqual(correctCreate2Address.toLocaleLowerCase());
338+
expect(await alice.provider.getCode(deployedAddress.deployedAddress)).toEqual(bytecode);
339+
});
340+
318341
afterAll(async () => {
319342
await testMaster.deinitialize();
320343
});

etc/env/base/contracts.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ RECURSION_NODE_LEVEL_VK_HASH = "0x1186ec268d49f1905f8d9c1e9d39fc33e98c74f91d91a2
2626
RECURSION_LEAF_LEVEL_VK_HASH = "0x101e08b00193e529145ee09823378ef51a3bc8966504064f1f6ba3f1ba863210"
2727
RECURSION_CIRCUITS_SET_VKS_HASH = "0x18c1639094f58177409186e8c48d9f577c9410901d2f1d486b3e7d6cf553ae4c"
2828
GENESIS_TX_HASH = "0xb99ebfea46cbe05a21cd80fe5597d97b204befc52a16303f579c607dc1ac2e2e"
29-
GENESIS_ROOT = "0x7fe280b1c2209f4b34a15db4cc74568f59db98d400c8e3f3282163acb74d4b14"
30-
GENESIS_BATCH_COMMITMENT = "0x62a99e2685b08bd81eef940a3698ffba6289ec77882d7ac6d5e7bcdbbe6351cd"
29+
GENESIS_ROOT = "0xa0aa5de6ded5c1911d5fee166ee17f3fef98c1ea796c608b9cbee4ce04aaf839"
30+
GENESIS_BATCH_COMMITMENT = "0x3f9ceab98b3baecaa77ba9681919ef822c5a2a6ba97c3be1a68712e1ae63c2ac"
3131
PRIORITY_TX_MAX_GAS_LIMIT = 72000000
3232
DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT = 10000000
33-
GENESIS_ROLLUP_LEAF_INDEX = "50"
33+
GENESIS_ROLLUP_LEAF_INDEX = "52"
3434
GENESIS_PROTOCOL_VERSION = "23"
3535
L1_WETH_BRIDGE_IMPL_ADDR = "0x5E6D086F5eC079ADFF4FB3774CDf3e8D6a34F7E9"
3636
L1_WETH_BRIDGE_PROXY_ADDR = "0x5E6D086F5eC079ADFF4FB3774CDf3e8D6a34F7E9"

0 commit comments

Comments
 (0)