Skip to content

Commit 9ffd7cf

Browse files
StanislavBreadlessvladbochokAntonD3koloz193benceharomi
authored
release v20: Short term fee model + 1.4.1 (#167)
Co-authored-by: vladbochok <vladbochok1@gmail.com> Co-authored-by: AntonD3 <74021421+AntonD3@users.noreply.github.com> Co-authored-by: Vlad Bochok <41153528+vladbochok@users.noreply.github.com> Co-authored-by: koloz <zach.kolodny@gmail.com> Co-authored-by: AntonD3 <antonv.dyadyuk@gmail.com> Co-authored-by: Bence Haromi <bence.haromi@gmail.com>
1 parent d55ea62 commit 9ffd7cf

File tree

118 files changed

+4187
-5686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+4187
-5686
lines changed

.github/workflows/l2-contracts-ci.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ jobs:
2020
- name: Install dependencies
2121
run: yarn
2222

23-
- name: Build artifacts
23+
- name: Build L2 artifacts
2424
run: yarn l2 build
2525

26+
- name: Build L1 artifacts
27+
run: yarn l1 build
28+
2629
- name: Create cache
2730
uses: actions/cache/save@v3
2831
with:
@@ -31,6 +34,9 @@ jobs:
3134
l2-contracts/artifacts-zk
3235
l2-contracts/cache-zk
3336
l2-contracts/typechain
37+
l1-contracts/artifacts
38+
l1-contracts/cache
39+
l1-contracts/typechain
3440
3541
lint:
3642
runs-on: ubuntu-latest
@@ -79,6 +85,9 @@ jobs:
7985
l2-contracts/artifacts-zk
8086
l2-contracts/cache-zk
8187
l2-contracts/typechain
88+
l1-contracts/artifacts
89+
l1-contracts/cache
90+
l1-contracts/typechain
8291
8392
- name: Run Era test node
8493
uses: dutterbutter/era-test-node-action@v0.1.3

.github/workflows/system-contracts-ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
- name: Use era-test-node for testing
101101
uses: dutterbutter/era-test-node-action@v0.1.3
102102
with:
103-
releaseTag: v0.0.1-alpha.boojum
103+
releaseTag: v0.0.1-vm1.4.1
104104

105105
- name: Install dependencies
106106
run: yarn

.markdownlintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ l2-contracts/node_modules
1010

1111
# system-contracts
1212
system-contracts/node_modules
13+
system-contracts/bootloader/test_infra/target

SystemConfig.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
{
2-
"L2_TX_MAX_GAS_LIMIT": 80000000,
3-
"MAX_PUBDATA_PER_BATCH": 110000,
4-
"PRIORITY_TX_MAX_PUBDATA": 99000,
5-
"FAIR_L2_GAS_PRICE": 500000000,
2+
"GUARANTEED_PUBDATA_BYTES": 2500,
3+
"MAX_TRANSACTIONS_IN_BATCH": 10000,
4+
"REQUIRED_L2_GAS_PRICE_PER_PUBDATA": 800,
65
"L1_GAS_PER_PUBDATA_BYTE": 17,
7-
"BATCH_OVERHEAD_L2_GAS": 1200000,
6+
"PRIORITY_TX_MAX_PUBDATA": 99000,
87
"BATCH_OVERHEAD_L1_GAS": 1000000,
9-
"MAX_TRANSACTIONS_IN_BATCH": 1024,
10-
"BOOTLOADER_TX_ENCODING_SPACE": 8740224,
118
"L1_TX_INTRINSIC_L2_GAS": 167157,
129
"L1_TX_INTRINSIC_PUBDATA": 88,
1310
"L1_TX_MIN_L2_GAS_BASE": 173484,
1411
"L1_TX_DELTA_544_ENCODING_BYTES": 1656,
1512
"L1_TX_DELTA_FACTORY_DEPS_L2_GAS": 2473,
1613
"L1_TX_DELTA_FACTORY_DEPS_PUBDATA": 64,
14+
"L2_TX_INTRINSIC_GAS": 14070,
15+
"L2_TX_INTRINSIC_PUBDATA": 0,
1716
"MAX_NEW_FACTORY_DEPS": 32,
18-
"REQUIRED_L2_GAS_PRICE_PER_PUBDATA": 800
17+
"MAX_GAS_PER_TRANSACTION": 80000000,
18+
"KECCAK_ROUND_COST_GAS": 40,
19+
"SHA256_ROUND_COST_GAS": 7,
20+
"ECRECOVER_COST_GAS": 7000,
21+
"PRIORITY_TX_MINIMAL_GAS_PRICE": 250000000,
22+
"PRIORITY_TX_MAX_GAS_PER_BATCH": 80000000,
23+
"PRIORITY_TX_PUBDATA_PER_BATCH": 120000,
24+
"PRIORITY_TX_BATCH_OVERHEAD_L1_GAS": 1000000
1925
}

docs/Overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ data from L2 and to prove that they were sent on L1 using only `l2ToL1log`. To s
149149
this trick:
150150

151151
- One of the system contracts accepts an arbitrary length message and sends a fixed length message with parameters
152-
`senderAddress == this`, `marker == true`, `key == msg.sender`, `value == keccak256(message)`.
152+
`senderAddress == this`, `isService == true`, `key == msg.sender`, `value == keccak256(message)`.
153153
- The contract on L1 accepts all sent messages and if the message came from this system contract it requires that the
154154
preimage of `value` be provided.
155155

l1-contracts/contracts/bridge/L1ERC20Bridge.sol

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22

33
pragma solidity 0.8.20;
44

5-
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
6-
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
5+
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
6+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
7+
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
78

8-
import "./interfaces/IL1BridgeLegacy.sol";
9-
import "./interfaces/IL1Bridge.sol";
10-
import "./interfaces/IL2Bridge.sol";
11-
import "./interfaces/IL2ERC20Bridge.sol";
9+
import {IL1BridgeLegacy} from "./interfaces/IL1BridgeLegacy.sol";
10+
import {IL1Bridge} from "./interfaces/IL1Bridge.sol";
11+
import {IL2Bridge} from "./interfaces/IL2Bridge.sol";
12+
import {IL2ERC20Bridge} from "./interfaces/IL2ERC20Bridge.sol";
1213

13-
import "./libraries/BridgeInitializationHelper.sol";
14+
import {BridgeInitializationHelper} from "./libraries/BridgeInitializationHelper.sol";
1415

15-
import "../zksync/interfaces/IZkSync.sol";
16-
import "../common/libraries/UnsafeBytes.sol";
17-
import "../common/libraries/L2ContractHelper.sol";
18-
import "../common/ReentrancyGuard.sol";
19-
import "../vendor/AddressAliasHelper.sol";
16+
import {IZkSync} from "../zksync/interfaces/IZkSync.sol";
17+
import {TxStatus} from "../zksync/interfaces/IMailbox.sol";
18+
import {L2Message} from "../zksync/Storage.sol";
19+
import {UnsafeBytes} from "../common/libraries/UnsafeBytes.sol";
20+
import {L2ContractHelper} from "../common/libraries/L2ContractHelper.sol";
21+
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";
22+
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol";
2023

2124
/// @author Matter Labs
2225
/// @custom:security-contact security@matterlabs.dev
@@ -31,11 +34,13 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard {
3134

3235
/// @dev A mapping L2 batch number => message number => flag
3336
/// @dev Used to indicate that zkSync L2 -> L1 message was already processed
34-
mapping(uint256 => mapping(uint256 => bool)) public isWithdrawalFinalized;
37+
mapping(uint256 l2BatchNumber => mapping(uint256 l2ToL1MessageNumber => bool isFinalized))
38+
public isWithdrawalFinalized;
3539

3640
/// @dev A mapping account => L1 token address => L2 deposit transaction hash => amount
3741
/// @dev Used for saving the number of deposited funds, to claim them in case the deposit transaction will fail
38-
mapping(address => mapping(address => mapping(bytes32 => uint256))) internal depositAmount;
42+
mapping(address account => mapping(address l1Token => mapping(bytes32 depositL2TxHash => uint256 amount)))
43+
internal depositAmount;
3944

4045
/// @dev The address of deployed L2 bridge counterpart
4146
address public l2Bridge;
@@ -46,14 +51,14 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard {
4651
/// @dev The bytecode hash of the L2 token contract
4752
bytes32 public l2TokenProxyBytecodeHash;
4853

49-
mapping(address => uint256) public __DEPRECATED_lastWithdrawalLimitReset;
54+
mapping(address => uint256) private __DEPRECATED_lastWithdrawalLimitReset;
5055

5156
/// @dev A mapping L1 token address => the accumulated withdrawn amount during the withdrawal limit window
52-
mapping(address => uint256) public __DEPRECATED_withdrawnAmountInWindow;
57+
mapping(address => uint256) private __DEPRECATED_withdrawnAmountInWindow;
5358

5459
/// @dev The accumulated deposited amount per user.
5560
/// @dev A mapping L1 token address => user address => the total deposited amount by the user
56-
mapping(address => mapping(address => uint256)) public totalDepositedAmountPerUser;
61+
mapping(address => mapping(address => uint256)) private __DEPRECATED_totalDepositedAmountPerUser;
5762

5863
/// @dev Contract is expected to be used as proxy implementation.
5964
/// @dev Initialize the implementation to prevent Parity hack.
@@ -119,14 +124,16 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard {
119124
_deployBridgeProxyFee,
120125
l2BridgeProxyBytecodeHash,
121126
l2BridgeProxyConstructorData,
122-
// No factory deps are needed for L2 bridge proxy, because it is already passed in previous step
127+
// No factory deps are needed for the L2 bridge proxy, because it is already passed in previous step
123128
new bytes[](0)
124129
);
125130
}
126131

127132
/// @notice Legacy deposit method with refunding the fee to the caller, use another `deposit` method instead.
128133
/// @dev Initiates a deposit by locking funds on the contract and sending the request
129-
/// of processing an L2 transaction where tokens would be minted
134+
/// of processing an L2 transaction where tokens would be minted.
135+
/// @dev If the token is bridged for the first time, the L2 token contract will be deployed. Note however, that the
136+
/// newly-deployed token does not support any custom logic, i.e. rebase tokens' functionality is not supported.
130137
/// @param _l2Receiver The account address that should receive funds on L2
131138
/// @param _l1Token The L1 token address which is deposited
132139
/// @param _amount The total amount of tokens to be bridged
@@ -146,6 +153,8 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard {
146153

147154
/// @notice Initiates a deposit by locking funds on the contract and sending the request
148155
/// of processing an L2 transaction where tokens would be minted
156+
/// @dev If the token is bridged for the first time, the L2 token contract will be deployed. Note however, that the
157+
/// newly-deployed token does not support any custom logic, i.e. rebase tokens' functionality is not supported.
149158
/// @param _l2Receiver The account address that should receive funds on L2
150159
/// @param _l1Token The L1 token address which is deposited
151160
/// @param _amount The total amount of tokens to be bridged
@@ -326,7 +335,7 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard {
326335

327336
/// @return The L2 token address that would be minted for deposit of the given L1 token
328337
function l2TokenAddress(address _l1Token) public view returns (address) {
329-
bytes32 constructorInputHash = keccak256(abi.encode(address(l2TokenBeacon), ""));
338+
bytes32 constructorInputHash = keccak256(abi.encode(l2TokenBeacon, ""));
330339
bytes32 salt = bytes32(uint256(uint160(_l1Token)));
331340

332341
return L2ContractHelper.computeCreate2Address(l2Bridge, salt, l2TokenProxyBytecodeHash, constructorInputHash);

l1-contracts/contracts/bridge/L1WethBridge.sol

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33
pragma solidity 0.8.20;
44

5-
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
5+
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
6+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
67

7-
import "./interfaces/IL1Bridge.sol";
8-
import "./interfaces/IL2WethBridge.sol";
9-
import "./interfaces/IL2Bridge.sol";
10-
import "./interfaces/IWETH9.sol";
11-
import "../zksync/interfaces/IZkSync.sol";
8+
import {IL1Bridge} from "./interfaces/IL1Bridge.sol";
9+
import {IL2WethBridge} from "./interfaces/IL2WethBridge.sol";
10+
import {IL2Bridge} from "./interfaces/IL2Bridge.sol";
11+
import {IWETH9} from "./interfaces/IWETH9.sol";
12+
import {IZkSync} from "../zksync/interfaces/IZkSync.sol";
1213

13-
import "./libraries/BridgeInitializationHelper.sol";
14+
import {BridgeInitializationHelper} from "./libraries/BridgeInitializationHelper.sol";
1415

15-
import "../common/libraries/UnsafeBytes.sol";
16-
import "../common/ReentrancyGuard.sol";
17-
import "../common/libraries/L2ContractHelper.sol";
16+
import {IMailbox} from "../zksync/interfaces/IMailbox.sol";
17+
import {L2Message} from "../zksync/Storage.sol";
18+
19+
import {UnsafeBytes} from "../common/libraries/UnsafeBytes.sol";
20+
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";
21+
import {L2ContractHelper} from "../common/libraries/L2ContractHelper.sol";
1822
import {L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR} from "../common/L2ContractAddresses.sol";
19-
import "../vendor/AddressAliasHelper.sol";
23+
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol";
2024

2125
/// @author Matter Labs
2226
/// @custom:security-contact security@matterlabs.dev
@@ -52,7 +56,8 @@ contract L1WethBridge is IL1Bridge, ReentrancyGuard {
5256

5357
/// @dev A mapping L2 batch number => message number => flag
5458
/// @dev Used to indicate that zkSync L2 -> L1 WETH message was already processed
55-
mapping(uint256 => mapping(uint256 => bool)) public isWithdrawalFinalized;
59+
mapping(uint256 l2BatchNumber => mapping(uint256 l2ToL1MessageNumber => bool isFinalized))
60+
public isWithdrawalFinalized;
5661

5762
/// @dev Contract is expected to be used as proxy implementation.
5863
/// @dev Initialize the implementation to prevent Parity hack.
@@ -68,9 +73,9 @@ contract L1WethBridge is IL1Bridge, ReentrancyGuard {
6873
/// @notice _factoryDeps[1] == a raw bytecode of proxy that is used as L2 WETH bridge
6974
/// @param _l2WethAddress Pre-calculated address of L2 WETH token
7075
/// @param _governor Address which can change L2 WETH token implementation and upgrade the bridge
71-
/// @param _deployBridgeImplementationFee The fee that will be paid for the L1 -> L2 transaction for deploying L2
76+
/// @param _deployBridgeImplementationFee The fee that will be paid for the L1 -> L2 transaction for deploying the L2
7277
/// bridge implementation
73-
/// @param _deployBridgeProxyFee The fee that will be paid for the L1 -> L2 transaction for deploying L2 bridge
78+
/// @param _deployBridgeProxyFee The fee that will be paid for the L1 -> L2 transaction for deploying the L2 bridge
7479
/// proxy
7580
function initialize(
7681
bytes[] calldata _factoryDeps,
@@ -122,7 +127,7 @@ contract L1WethBridge is IL1Bridge, ReentrancyGuard {
122127
_deployBridgeProxyFee,
123128
l2WethBridgeProxyBytecodeHash,
124129
l2WethBridgeProxyConstructorData,
125-
// No factory deps are needed for L2 bridge proxy, because it is already passed in the previous step
130+
// No factory deps are needed for the L2 bridge proxy, because it is already passed in the previous step
126131
new bytes[](0)
127132
);
128133
}

l1-contracts/contracts/bridge/interfaces/IL1Bridge.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
pragma solidity 0.8.20;
44

5+
/// @title L1 Bridge contract interface
56
/// @author Matter Labs
7+
/// @custom:security-contact security@matterlabs.dev
68
interface IL1Bridge {
79
event DepositInitiated(
810
bytes32 indexed l2DepositTxHash,

l1-contracts/contracts/bridge/interfaces/IL1BridgeLegacy.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
pragma solidity 0.8.20;
44

5+
/// @title L1 Bridge contract legacy interface
56
/// @author Matter Labs
7+
/// @custom:security-contact security@matterlabs.dev
68
interface IL1BridgeLegacy {
79
function deposit(
810
address _l2Receiver,

l1-contracts/contracts/common/L2ContractAddresses.sol

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,3 @@ address constant L2_KNOWN_CODE_STORAGE_SYSTEM_CONTRACT_ADDR = address(0x8004);
2828

2929
/// @dev The address of the context system contract
3030
address constant L2_SYSTEM_CONTEXT_SYSTEM_CONTRACT_ADDR = address(0x800b);
31-
32-
/// @dev The address of the bytecode compressor system contract
33-
address constant L2_BYTECODE_COMPRESSOR_SYSTEM_CONTRACT_ADDR = address(0x800e);

l1-contracts/contracts/common/libraries/L2ContractHelper.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pragma solidity 0.8.20;
99
*/
1010
library L2ContractHelper {
1111
/// @dev The prefix used to create CREATE2 addresses.
12-
bytes32 constant CREATE2_PREFIX = keccak256("zksyncCreate2");
12+
bytes32 private constant CREATE2_PREFIX = keccak256("zksyncCreate2");
1313

1414
/// @notice Validate the bytecode format and calculate its hash.
1515
/// @param _bytecode The bytecode to hash.

l1-contracts/contracts/dev-contracts/test/CustomUpgradeTest.sol

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@ contract CustomUpgradeTest is BaseZkSyncUpgrade {
1111
/// @notice Placeholder function for custom logic for upgrading L1 contract.
1212
/// Typically this function will never be used.
1313
/// @param _customCallDataForUpgrade Custom data for upgrade, which may be interpreted differently for each upgrade.
14-
function _upgradeL1Contract(bytes calldata _customCallDataForUpgrade) internal {
14+
function _upgradeL1Contract(bytes calldata _customCallDataForUpgrade) internal override {
1515
emit Test();
1616
}
1717

1818
/// @notice placeholder function for custom logic for post-upgrade logic.
1919
/// Typically this function will never be used.
2020
/// @param _customCallDataForUpgrade Custom data for an upgrade, which may be interpreted differently for each
2121
/// upgrade.
22-
function _postUpgrade(bytes calldata _customCallDataForUpgrade) internal virtual {}
22+
function _postUpgrade(bytes calldata _customCallDataForUpgrade) internal override {}
2323

2424
/// @notice The main function that will be called by the upgrade proxy.
2525
/// @param _proposedUpgrade The upgrade to be executed.
2626
function upgrade(ProposedUpgrade calldata _proposedUpgrade) public override returns (bytes32) {
27-
super.upgrade(_proposedUpgrade);
28-
2927
_setNewProtocolVersion(_proposedUpgrade.newProtocolVersion);
3028
_upgradeL1Contract(_proposedUpgrade.l1ContractsUpgradeCalldata);
3129
_upgradeVerifier(_proposedUpgrade.verifier, _proposedUpgrade.verifierParams);

l1-contracts/contracts/dev-contracts/test/L1ERC20BridgeTest.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
pragma solidity 0.8.20;
44

55
import "../../bridge/L1ERC20Bridge.sol";
6+
import {IMailbox} from "../../zksync/interfaces/IMailbox.sol";
67

78
/// @author Matter Labs
89
contract L1ERC20BridgeTest is L1ERC20Bridge {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity 0.8.20;
4+
5+
import "../../zksync/facets/Mailbox.sol";
6+
import "../../zksync/Config.sol";
7+
8+
contract MailboxFacetTest is MailboxFacet {
9+
constructor() {
10+
s.governor = msg.sender;
11+
}
12+
13+
function setFeeParams(FeeParams memory _feeParams) external {
14+
s.feeParams = _feeParams;
15+
}
16+
17+
function getL2GasPrice(uint256 _l1GasPrice) external view returns (uint256) {
18+
return _deriveL2GasPrice(_l1GasPrice, REQUIRED_L2_GAS_PRICE_PER_PUBDATA);
19+
}
20+
}

0 commit comments

Comments
 (0)