-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
149 changed files
with
5,438 additions
and
6,687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Build and release | ||
|
||
on: | ||
push: | ||
branches: | ||
- "*" | ||
|
||
jobs: | ||
build-contracts: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.18.0 | ||
cache: yarn | ||
|
||
- name: Init | ||
id: init | ||
run: | | ||
yarn | ||
echo "release_tag=$(echo ${GITHUB_REF#refs/heads/})-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
- name: Build contracts | ||
run: | | ||
yarn l1 build | ||
yarn l2 build | ||
yarn sc build | ||
- name: Prepare artifacts | ||
run: | | ||
tar -czvf l1-contracts.tar.gz ./l1-contracts | ||
tar -czvf l2-contracts.tar.gz ./l2-contracts | ||
tar -czvf system-contracts.tar.gz ./system-contracts | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
tag_name: ${{ steps.init.outputs.release_tag }} | ||
fail_on_unmatched_files: true | ||
body: "" | ||
files: | | ||
l1-contracts.tar.gz | ||
l2-contracts.tar.gz | ||
system-contracts.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,6 @@ name: L1 contracts CI | |
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- dev | ||
- main | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,6 @@ name: L2 contracts CI | |
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- dev | ||
- main | ||
|
||
jobs: | ||
build: | ||
|
@@ -24,9 +20,12 @@ jobs: | |
- name: Install dependencies | ||
run: yarn | ||
|
||
- name: Build artifacts | ||
- name: Build L2 artifacts | ||
run: yarn l2 build | ||
|
||
- name: Build L1 artifacts | ||
run: yarn l1 build | ||
|
||
- name: Create cache | ||
uses: actions/cache/save@v3 | ||
with: | ||
|
@@ -35,6 +34,9 @@ jobs: | |
l2-contracts/artifacts-zk | ||
l2-contracts/cache-zk | ||
l2-contracts/typechain | ||
l1-contracts/artifacts | ||
l1-contracts/cache | ||
l1-contracts/typechain | ||
lint: | ||
runs-on: ubuntu-latest | ||
|
@@ -83,6 +85,9 @@ jobs: | |
l2-contracts/artifacts-zk | ||
l2-contracts/cache-zk | ||
l2-contracts/typechain | ||
l1-contracts/artifacts | ||
l1-contracts/cache | ||
l1-contracts/typechain | ||
- name: Run Era test node | ||
uses: dutterbutter/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,6 @@ name: System contracts CI | |
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- dev | ||
- main | ||
|
||
jobs: | ||
build: | ||
|
@@ -104,7 +100,7 @@ jobs: | |
- name: Use era-test-node for testing | ||
uses: dutterbutter/[email protected] | ||
with: | ||
releaseTag: v0.0.1-alpha.boojum | ||
releaseTag: v0.0.1-vm1.4.1 | ||
|
||
- name: Install dependencies | ||
run: yarn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "l1-contracts/lib/forge-std"] | ||
path = l1-contracts/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "l1-contracts/lib/murky"] | ||
path = l1-contracts/lib/murky | ||
url = https://github.com/dmfxyz/murky |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
{ | ||
"L2_TX_MAX_GAS_LIMIT": 80000000, | ||
"MAX_PUBDATA_PER_BATCH": 110000, | ||
"PRIORITY_TX_MAX_PUBDATA": 99000, | ||
"FAIR_L2_GAS_PRICE": 500000000, | ||
"GUARANTEED_PUBDATA_BYTES": 2500, | ||
"MAX_TRANSACTIONS_IN_BATCH": 10000, | ||
"REQUIRED_L2_GAS_PRICE_PER_PUBDATA": 800, | ||
"L1_GAS_PER_PUBDATA_BYTE": 17, | ||
"BATCH_OVERHEAD_L2_GAS": 1200000, | ||
"PRIORITY_TX_MAX_PUBDATA": 99000, | ||
"BATCH_OVERHEAD_L1_GAS": 1000000, | ||
"MAX_TRANSACTIONS_IN_BATCH": 1024, | ||
"BOOTLOADER_TX_ENCODING_SPACE": 8740224, | ||
"L1_TX_INTRINSIC_L2_GAS": 167157, | ||
"L1_TX_INTRINSIC_PUBDATA": 88, | ||
"L1_TX_MIN_L2_GAS_BASE": 173484, | ||
"L1_TX_DELTA_544_ENCODING_BYTES": 1656, | ||
"L1_TX_DELTA_FACTORY_DEPS_L2_GAS": 2473, | ||
"L1_TX_DELTA_FACTORY_DEPS_PUBDATA": 64, | ||
"L2_TX_INTRINSIC_GAS": 14070, | ||
"L2_TX_INTRINSIC_PUBDATA": 0, | ||
"MAX_NEW_FACTORY_DEPS": 32, | ||
"REQUIRED_L2_GAS_PRICE_PER_PUBDATA": 800 | ||
"MAX_GAS_PER_TRANSACTION": 80000000, | ||
"KECCAK_ROUND_COST_GAS": 40, | ||
"SHA256_ROUND_COST_GAS": 7, | ||
"ECRECOVER_COST_GAS": 7000, | ||
"PRIORITY_TX_MINIMAL_GAS_PRICE": 500000000, | ||
"PRIORITY_TX_MAX_GAS_PER_BATCH": 80000000, | ||
"PRIORITY_TX_PUBDATA_PER_BATCH": 100000, | ||
"PRIORITY_TX_BATCH_OVERHEAD_L1_GAS": 1000000 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,24 @@ | |
|
||
pragma solidity 0.8.20; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; | ||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
import "./interfaces/IL1BridgeLegacy.sol"; | ||
import "./interfaces/IL1Bridge.sol"; | ||
import "./interfaces/IL2Bridge.sol"; | ||
import "./interfaces/IL2ERC20Bridge.sol"; | ||
import {IL1BridgeLegacy} from "./interfaces/IL1BridgeLegacy.sol"; | ||
import {IL1Bridge} from "./interfaces/IL1Bridge.sol"; | ||
import {IL2Bridge} from "./interfaces/IL2Bridge.sol"; | ||
import {IL2ERC20Bridge} from "./interfaces/IL2ERC20Bridge.sol"; | ||
|
||
import "./libraries/BridgeInitializationHelper.sol"; | ||
import {BridgeInitializationHelper} from "./libraries/BridgeInitializationHelper.sol"; | ||
|
||
import "../zksync/interfaces/IZkSync.sol"; | ||
import "../common/libraries/UnsafeBytes.sol"; | ||
import "../common/libraries/L2ContractHelper.sol"; | ||
import "../common/ReentrancyGuard.sol"; | ||
import "../vendor/AddressAliasHelper.sol"; | ||
import {IZkSync} from "../zksync/interfaces/IZkSync.sol"; | ||
import {TxStatus} from "../zksync/interfaces/IMailbox.sol"; | ||
import {L2Message} from "../zksync/Storage.sol"; | ||
import {UnsafeBytes} from "../common/libraries/UnsafeBytes.sol"; | ||
import {L2ContractHelper} from "../common/libraries/L2ContractHelper.sol"; | ||
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol"; | ||
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
|
@@ -31,11 +34,13 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard { | |
|
||
/// @dev A mapping L2 batch number => message number => flag | ||
/// @dev Used to indicate that zkSync L2 -> L1 message was already processed | ||
mapping(uint256 => mapping(uint256 => bool)) public isWithdrawalFinalized; | ||
mapping(uint256 l2BatchNumber => mapping(uint256 l2ToL1MessageNumber => bool isFinalized)) | ||
public isWithdrawalFinalized; | ||
|
||
/// @dev A mapping account => L1 token address => L2 deposit transaction hash => amount | ||
/// @dev Used for saving the number of deposited funds, to claim them in case the deposit transaction will fail | ||
mapping(address => mapping(address => mapping(bytes32 => uint256))) internal depositAmount; | ||
mapping(address account => mapping(address l1Token => mapping(bytes32 depositL2TxHash => uint256 amount))) | ||
internal depositAmount; | ||
|
||
/// @dev The address of deployed L2 bridge counterpart | ||
address public l2Bridge; | ||
|
@@ -46,14 +51,14 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard { | |
/// @dev The bytecode hash of the L2 token contract | ||
bytes32 public l2TokenProxyBytecodeHash; | ||
|
||
mapping(address => uint256) public __DEPRECATED_lastWithdrawalLimitReset; | ||
mapping(address => uint256) private __DEPRECATED_lastWithdrawalLimitReset; | ||
|
||
/// @dev A mapping L1 token address => the accumulated withdrawn amount during the withdrawal limit window | ||
mapping(address => uint256) public __DEPRECATED_withdrawnAmountInWindow; | ||
mapping(address => uint256) private __DEPRECATED_withdrawnAmountInWindow; | ||
|
||
/// @dev The accumulated deposited amount per user. | ||
/// @dev A mapping L1 token address => user address => the total deposited amount by the user | ||
mapping(address => mapping(address => uint256)) public totalDepositedAmountPerUser; | ||
mapping(address => mapping(address => uint256)) private __DEPRECATED_totalDepositedAmountPerUser; | ||
|
||
/// @dev Contract is expected to be used as proxy implementation. | ||
/// @dev Initialize the implementation to prevent Parity hack. | ||
|
@@ -119,20 +124,23 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard { | |
_deployBridgeProxyFee, | ||
l2BridgeProxyBytecodeHash, | ||
l2BridgeProxyConstructorData, | ||
// No factory deps are needed for L2 bridge proxy, because it is already passed in previous step | ||
// No factory deps are needed for the L2 bridge proxy, because it is already passed in previous step | ||
new bytes[](0) | ||
); | ||
} | ||
|
||
/// @notice Legacy deposit method with refunding the fee to the caller, use another `deposit` method instead. | ||
/// @dev Initiates a deposit by locking funds on the contract and sending the request | ||
/// of processing an L2 transaction where tokens would be minted | ||
/// of processing an L2 transaction where tokens would be minted. | ||
/// @dev If the token is bridged for the first time, the L2 token contract will be deployed. Note however, that the | ||
/// newly-deployed token does not support any custom logic, i.e. rebase tokens' functionality is not supported. | ||
/// @param _l2Receiver The account address that should receive funds on L2 | ||
/// @param _l1Token The L1 token address which is deposited | ||
/// @param _amount The total amount of tokens to be bridged | ||
/// @param _l2TxGasLimit The L2 gas limit to be used in the corresponding L2 transaction | ||
/// @param _l2TxGasPerPubdataByte The gasPerPubdataByteLimit to be used in the corresponding L2 transaction | ||
/// @return l2TxHash The L2 transaction hash of deposit finalization | ||
/// NOTE: the function doesn't use `nonreentrant` modifier, because the inner method does. | ||
function deposit( | ||
address _l2Receiver, | ||
address _l1Token, | ||
|
@@ -145,6 +153,8 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard { | |
|
||
/// @notice Initiates a deposit by locking funds on the contract and sending the request | ||
/// of processing an L2 transaction where tokens would be minted | ||
/// @dev If the token is bridged for the first time, the L2 token contract will be deployed. Note however, that the | ||
/// newly-deployed token does not support any custom logic, i.e. rebase tokens' functionality is not supported. | ||
/// @param _l2Receiver The account address that should receive funds on L2 | ||
/// @param _l1Token The L1 token address which is deposited | ||
/// @param _amount The total amount of tokens to be bridged | ||
|
@@ -325,7 +335,7 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard { | |
|
||
/// @return The L2 token address that would be minted for deposit of the given L1 token | ||
function l2TokenAddress(address _l1Token) public view returns (address) { | ||
bytes32 constructorInputHash = keccak256(abi.encode(address(l2TokenBeacon), "")); | ||
bytes32 constructorInputHash = keccak256(abi.encode(l2TokenBeacon, "")); | ||
bytes32 salt = bytes32(uint256(uint160(_l1Token))); | ||
|
||
return L2ContractHelper.computeCreate2Address(l2Bridge, salt, l2TokenProxyBytecodeHash, constructorInputHash); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,25 @@ | |
|
||
pragma solidity 0.8.20; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
import "./interfaces/IL1Bridge.sol"; | ||
import "./interfaces/IL2WethBridge.sol"; | ||
import "./interfaces/IL2Bridge.sol"; | ||
import "./interfaces/IWETH9.sol"; | ||
import "../zksync/interfaces/IZkSync.sol"; | ||
import {IL1Bridge} from "./interfaces/IL1Bridge.sol"; | ||
import {IL2WethBridge} from "./interfaces/IL2WethBridge.sol"; | ||
import {IL2Bridge} from "./interfaces/IL2Bridge.sol"; | ||
import {IWETH9} from "./interfaces/IWETH9.sol"; | ||
import {IZkSync} from "../zksync/interfaces/IZkSync.sol"; | ||
|
||
import "./libraries/BridgeInitializationHelper.sol"; | ||
import {BridgeInitializationHelper} from "./libraries/BridgeInitializationHelper.sol"; | ||
|
||
import "../common/libraries/UnsafeBytes.sol"; | ||
import "../common/ReentrancyGuard.sol"; | ||
import "../common/libraries/L2ContractHelper.sol"; | ||
import {IMailbox} from "../zksync/interfaces/IMailbox.sol"; | ||
import {L2Message} from "../zksync/Storage.sol"; | ||
|
||
import {UnsafeBytes} from "../common/libraries/UnsafeBytes.sol"; | ||
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol"; | ||
import {L2ContractHelper} from "../common/libraries/L2ContractHelper.sol"; | ||
import {L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR} from "../common/L2ContractAddresses.sol"; | ||
import "../vendor/AddressAliasHelper.sol"; | ||
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
|
@@ -52,7 +56,8 @@ contract L1WethBridge is IL1Bridge, ReentrancyGuard { | |
|
||
/// @dev A mapping L2 batch number => message number => flag | ||
/// @dev Used to indicate that zkSync L2 -> L1 WETH message was already processed | ||
mapping(uint256 => mapping(uint256 => bool)) public isWithdrawalFinalized; | ||
mapping(uint256 l2BatchNumber => mapping(uint256 l2ToL1MessageNumber => bool isFinalized)) | ||
public isWithdrawalFinalized; | ||
|
||
/// @dev Contract is expected to be used as proxy implementation. | ||
/// @dev Initialize the implementation to prevent Parity hack. | ||
|
@@ -68,9 +73,9 @@ contract L1WethBridge is IL1Bridge, ReentrancyGuard { | |
/// @notice _factoryDeps[1] == a raw bytecode of proxy that is used as L2 WETH bridge | ||
/// @param _l2WethAddress Pre-calculated address of L2 WETH token | ||
/// @param _governor Address which can change L2 WETH token implementation and upgrade the bridge | ||
/// @param _deployBridgeImplementationFee The fee that will be paid for the L1 -> L2 transaction for deploying L2 | ||
/// @param _deployBridgeImplementationFee The fee that will be paid for the L1 -> L2 transaction for deploying the L2 | ||
/// bridge implementation | ||
/// @param _deployBridgeProxyFee The fee that will be paid for the L1 -> L2 transaction for deploying L2 bridge | ||
/// @param _deployBridgeProxyFee The fee that will be paid for the L1 -> L2 transaction for deploying the L2 bridge | ||
/// proxy | ||
function initialize( | ||
bytes[] calldata _factoryDeps, | ||
|
@@ -122,7 +127,7 @@ contract L1WethBridge is IL1Bridge, ReentrancyGuard { | |
_deployBridgeProxyFee, | ||
l2WethBridgeProxyBytecodeHash, | ||
l2WethBridgeProxyConstructorData, | ||
// No factory deps are needed for L2 bridge proxy, because it is already passed in the previous step | ||
// No factory deps are needed for the L2 bridge proxy, because it is already passed in the previous step | ||
new bytes[](0) | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
|
||
pragma solidity 0.8.20; | ||
|
||
/// @title L1 Bridge contract interface | ||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
interface IL1Bridge { | ||
event DepositInitiated( | ||
bytes32 indexed l2DepositTxHash, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
|
||
pragma solidity 0.8.20; | ||
|
||
/// @title L1 Bridge contract legacy interface | ||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
interface IL1BridgeLegacy { | ||
function deposit( | ||
address _l2Receiver, | ||
|
Oops, something went wrong.