-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'kl/sync-layer-reorg' of ssh://github.com/matter-labs/er…
…a-contracts into gw-audit-2-sls
- Loading branch information
Showing
167 changed files
with
8,680 additions
and
2,352 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 |
---|---|---|
|
@@ -22,6 +22,9 @@ jobs: | |
node-version: 18.18.0 | ||
cache: yarn | ||
|
||
- name: Use Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
|
||
- name: Install dependencies | ||
run: yarn | ||
|
||
|
@@ -39,19 +42,22 @@ jobs: | |
- name: Build l1 artifacts | ||
run: yarn l1 build | ||
|
||
- name: Build da-contracts artifacts | ||
run: yarn da build:foundry | ||
|
||
- name: Create cache | ||
uses: actions/cache/save@v3 | ||
with: | ||
key: artifacts-l1-${{ github.sha }} | ||
path: | | ||
da-contracts/out | ||
l1-contracts/artifacts | ||
l1-contracts/artifacts-zk | ||
l1-contracts/cache | ||
l1-contracts/typechain | ||
l2-contracts/artifacts-zk | ||
l2-contracts/cache-zk | ||
l2-contracts/typechain | ||
l1-contracts/lib | ||
lint: | ||
runs-on: ubuntu-latest | ||
|
@@ -100,14 +106,14 @@ jobs: | |
fail-on-cache-miss: true | ||
key: artifacts-l1-${{ github.sha }} | ||
path: | | ||
da-contracts/out | ||
l1-contracts/artifacts | ||
l1-contracts/artifacts-zk | ||
l1-contracts/cache | ||
l1-contracts/typechain | ||
l2-contracts/artifacts-zk | ||
l2-contracts/cache-zk | ||
l2-contracts/typechain | ||
l1-contracts/lib | ||
- name: Run tests | ||
working-directory: ./l1-contracts | ||
|
@@ -141,14 +147,14 @@ jobs: | |
fail-on-cache-miss: true | ||
key: artifacts-l1-${{ github.sha }} | ||
path: | | ||
da-contracts/out | ||
l1-contracts/artifacts | ||
l1-contracts/artifacts-zk | ||
l1-contracts/cache | ||
l1-contracts/typechain | ||
l2-contracts/artifacts-zk | ||
l2-contracts/cache-zk | ||
l2-contracts/typechain | ||
l1-contracts/lib | ||
- name: Install foundry zksync | ||
run: | | ||
|
@@ -191,14 +197,14 @@ jobs: | |
fail-on-cache-miss: true | ||
key: artifacts-l1-${{ github.sha }} | ||
path: | | ||
da-contracts/out | ||
l1-contracts/artifacts | ||
l1-contracts/artifacts-zk | ||
l1-contracts/cache | ||
l1-contracts/typechain | ||
l2-contracts/artifacts-zk | ||
l2-contracts/cache-zk | ||
l2-contracts/typechain | ||
l1-contracts/lib | ||
- name: Build L2 contracts | ||
run: yarn l2 build | ||
|
@@ -258,49 +264,50 @@ jobs: | |
fail-on-cache-miss: true | ||
key: artifacts-l1-${{ github.sha }} | ||
path: | | ||
da-contracts/out | ||
l1-contracts/artifacts | ||
l1-contracts/artifacts-zk | ||
l1-contracts/cache | ||
l1-contracts/typechain | ||
l2-contracts/artifacts-zk | ||
l2-contracts/cache-zk | ||
l2-contracts/typechain | ||
l1-contracts/lib | ||
- name: Run coverage | ||
run: FOUNDRY_PROFILE=default yarn test:foundry && FOUNDRY_PROFILE=default yarn coverage:foundry --report summary --report lcov | ||
|
||
# To ignore coverage for certain directories modify the paths in this step as needed. The | ||
# below default ignores coverage results for the test and script directories. Alternatively, | ||
# to include coverage in all directories, comment out this step. Note that because this | ||
# filtering applies to the lcov file, the summary table generated in the previous step will | ||
# still include all files and directories. | ||
# The `--rc lcov_branch_coverage=1` part keeps branch info in the filtered report, since lcov | ||
# defaults to removing branch info. | ||
- name: Filter directories | ||
run: | | ||
sudo apt update && sudo apt install -y lcov | ||
lcov --remove lcov.info 'test/*' 'contracts/dev-contracts/*' '../lib/forge-std/*' '../lib/murky/*' 'lib/*' '../lib/*' 'lib/' --output-file lcov.info --rc lcov_branch_coverage=1 | ||
# This step posts a detailed coverage report as a comment and deletes previous comments on | ||
# each push. The below step is used to fail coverage if the specified coverage threshold is | ||
# not met. The below step can post a comment (when it's `github-token` is specified) but it's | ||
# not as useful, and this action cannot fail CI based on a minimum coverage threshold, which | ||
# is why we use both in this way. | ||
- name: Post coverage report | ||
if: github.event_name == 'pull_request' # This action fails when ran outside of a pull request. | ||
uses: romeovs/[email protected] | ||
with: | ||
delete-old-comments: true | ||
lcov-file: ./l1-contracts/lcov.info | ||
github-token: ${{ secrets.GITHUB_TOKEN }} # Adds a coverage summary comment to the PR. | ||
|
||
- name: Verify minimum coverage | ||
uses: zgosalvez/github-actions-report-lcov@v2 | ||
with: | ||
coverage-files: ./l1-contracts/lcov.info | ||
working-directory: l1-contracts | ||
minimum-coverage: 85 # Set coverage threshold. | ||
# TODO: fix filtering directories | ||
# # To ignore coverage for certain directories modify the paths in this step as needed. The | ||
# # below default ignores coverage results for the test and script directories. Alternatively, | ||
# # to include coverage in all directories, comment out this step. Note that because this | ||
# # filtering applies to the lcov file, the summary table generated in the previous step will | ||
# # still include all files and directories. | ||
# # The `--rc lcov_branch_coverage=1` part keeps branch info in the filtered report, since lcov | ||
# # defaults to removing branch info. | ||
# - name: Filter directories | ||
# run: | | ||
# sudo apt update && sudo apt install -y lcov | ||
# lcov --remove lcov.info 'test/*' 'contracts/dev-contracts/*' '../lib/forge-std/*' '../lib/murky/*' 'lib/*' '../lib/*' 'lib/' 'deploy-scripts/*' --output-file lcov.info --rc lcov_branch_coverage=1 | ||
|
||
# # This step posts a detailed coverage report as a comment and deletes previous comments on | ||
# # each push. The below step is used to fail coverage if the specified coverage threshold is | ||
# # not met. The below step can post a comment (when it's `github-token` is specified) but it's | ||
# # not as useful, and this action cannot fail CI based on a minimum coverage threshold, which | ||
# # is why we use both in this way. | ||
# - name: Post coverage report | ||
# if: github.event_name == 'pull_request' # This action fails when ran outside of a pull request. | ||
# uses: romeovs/[email protected] | ||
# with: | ||
# delete-old-comments: true | ||
# lcov-file: ./l1-contracts/lcov.info | ||
# github-token: ${{ secrets.GITHUB_TOKEN }} # Adds a coverage summary comment to the PR. | ||
|
||
# - name: Verify minimum coverage | ||
# uses: zgosalvez/github-actions-report-lcov@v2 | ||
# with: | ||
# coverage-files: ./l1-contracts/lcov.info | ||
# working-directory: l1-contracts | ||
# minimum-coverage: 85 # Set coverage threshold. | ||
|
||
gas-report: | ||
needs: [build, lint] | ||
|
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
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
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ import {IBridgedStandardToken} from "./interfaces/IBridgedStandardToken.sol"; | |
import {Unauthorized, NonSequentialVersion, ZeroAddress} from "../common/L1ContractErrors.sol"; | ||
import {L2_NATIVE_TOKEN_VAULT_ADDR} from "../common/L2ContractAddresses.sol"; | ||
import {DataEncoding} from "../common/libraries/DataEncoding.sol"; | ||
import {INativeTokenVault} from "../bridge/ntv/INativeTokenVault.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
|
@@ -43,13 +44,20 @@ contract BridgedStandardERC20 is ERC20PermitUpgradeable, IBridgedStandardToken, | |
/// @dev Address of the native token vault that is used as trustee who can mint/burn tokens | ||
address public nativeTokenVault; | ||
|
||
/// @dev The assetId of the token. | ||
bytes32 public assetId; | ||
|
||
/// @dev This also sets the native token vault to the default value if it is not set. | ||
/// It is not set only on the L2s for legacy tokens. | ||
modifier onlyNTV() { | ||
address ntv = nativeTokenVault; | ||
if (ntv == address(0)) { | ||
ntv = L2_NATIVE_TOKEN_VAULT_ADDR; | ||
nativeTokenVault = L2_NATIVE_TOKEN_VAULT_ADDR; | ||
assetId = DataEncoding.encodeNTVAssetId( | ||
INativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).L1_CHAIN_ID(), | ||
originToken | ||
); | ||
} | ||
if (msg.sender != ntv) { | ||
revert Unauthorized(msg.sender); | ||
|
@@ -74,14 +82,20 @@ contract BridgedStandardERC20 is ERC20PermitUpgradeable, IBridgedStandardToken, | |
|
||
/// @notice Initializes a contract token for later use. Expected to be used in the proxy. | ||
/// @dev Stores the L1 address of the bridge and set `name`/`symbol`/`decimals` getters that L1 token has. | ||
/// @param _assetId The assetId of the token. | ||
/// @param _originToken Address of the origin token that can be deposited to mint this bridged token | ||
/// @param _data The additional data that the L1 bridge provide for initialization. | ||
/// In this case, it is packed `name`/`symbol`/`decimals` of the L1 token. | ||
function bridgeInitialize(address _originToken, bytes calldata _data) external initializer { | ||
function bridgeInitialize( | ||
bytes32 _assetId, | ||
address _originToken, | ||
bytes calldata _data | ||
) external initializer { | ||
if (_originToken == address(0)) { | ||
revert ZeroAddress(); | ||
} | ||
originToken = _originToken; | ||
assetId = _assetId; | ||
|
||
nativeTokenVault = msg.sender; | ||
|
||
|
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
Oops, something went wrong.