Skip to content

Commit

Permalink
Merge branch 'dev' into boojum-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
benceharomi committed Sep 27, 2023
2 parents 3dd33b9 + b74757d commit c2dc75a
Show file tree
Hide file tree
Showing 33 changed files with 613 additions and 249 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
name: Scripts-Related Bug Report
about: Use this template for reporting script-related bugs. For contract-related bugs, see our security policy.
name: Bug report
about: Use this template for reporting issues
title: ''
labels: bug
assignees: ''
---

### 🐛 Script Bug Report
### 🐛 Bug Report

#### 📝 Description

Expand Down
93 changes: 86 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,105 @@
name: CI

on:
pull_request
on: pull_request

jobs:
lint:
runs-on: ubuntu-latest

defaults:
run:
working-directory: ethereum

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
cache-dependency-path: ethereum/yarn.lock

- name: Install yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn install

- name: Lint
run: yarn lint

build:
runs-on: ubuntu-latest

defaults:
run:
working-directory: ethereum

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
cache-dependency-path: ethereum/yarn.lock

- name: Install yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn install

- name: Build artifacts
run: yarn build

- name: Create cache
uses: actions/cache/save@v3
with:
key: artifacts-${{ github.sha }}
path: |
ethereum/artifacts
ethereum/cache
ethereum/typechain
test:
needs: [build, lint]
runs-on: ubuntu-latest

defaults:
run:
working-directory: ethereum

steps:
- uses: actions/checkout@v3
- name: Checkout the repository
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.15.1'
node-version: 18.18.0
cache: yarn
cache-dependency-path: ethereum/yarn.lock

- name: Install yarn
run: npm install -g yarn

- name: Install dependencies
run: cd ethereum && yarn install
run: yarn install

- name: Restore artifacts cache
uses: actions/cache/restore@v3
with:
fail-on-cache-miss: true
key: artifacts-${{ github.sha }}
path: |
ethereum/artifacts
ethereum/cache
ethereum/typechain
- name: Run tests
working-directory: ethereum
run: yarn test
run: yarn test --no-compile
7 changes: 3 additions & 4 deletions .github/workflows/nodejs-license.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: CI
name: Node license check

on:
- pull_request
on: pull_request

env:
ALLOWED_LICENSES: >
Expand Down Expand Up @@ -49,7 +48,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16.15.1'
node-version: 18.18.0

- name: Install yarn
run: npm install -g yarn license-checker
Expand Down
74 changes: 74 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Security Policy

We truly appreciate efforts to discover and disclose security issues responsibly!

## Vulnerabilities

If you'd like to report a security issue in the repositories of matter-labs organization, please proceed to our
[Bug Bounty Program on Immunefi](https://era.zksync.io/docs/reference/troubleshooting/audit-bug-bounty.html#bug-bounty-program).

## Other Security Issues

We take an impact-first approach instead of a rules-first approach. Therefore, if you believe you found the impactful
issue but can't report it via the Bug Bounty, please email us at
[[email protected]](mailto:[email protected]).

### PGP Key

The following PGP key may be used to communicate sensitive information to developers:

Fingerprint: `5FED B2D0 EA2C 4906 DD66 71D7 A2C5 0B40 CE3C F297`

```
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBGEBmQkBEAD6tlkBEZFMvR8kOgxXX857nC2+oTik6TopJz4uCskuqDaeldMy
l+26BBzLkIeO1loS+bzVgnNFJRrGt9gv98MzNEHJVv6D7GsSLlUX/pz7Lxn0J4ry
o5XIk3MQTCUBdaXGs6GBLl5Xe8o+zNj4MKd4zjgDLinITNlE/YZCDsXyvYS3YFTQ
cwaUTNlawkKgw4BLaEqwB2JuyEhI9wx5X7ibjFL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/n8AmLQb2bcpKSqpaJwMbmfEyr5MDm8xnsBTfx3u6kgaLOWfKxjLQ6PM7kgIMdi4
bfaRRuSEI1/R6c/hNpiGnzAeeexldH1we+eH1IVmh4crdat49S2xh7Qlv9ahvgsP
LfKl3rJ+aaX/Ok0AHzhvSfhFpPr1gAaGeaRt+rhlZsx2QyG4Ez8p2nDAcAzPiB3T
73ENoBIX6mTPfPm1UgrRyFKBqtUzAodz66j3r6ebBlWzIRg8iZenVMAxzjINAsxN
w1Bzfgsi5ZespfsSlmEaa7jJkqqDuEcLa2YuiFAue7Euqwz1aGeq1GfTicQioSCb
Ur/LGyz2Mj3ykbaP8p5mFVcUN51yQy6OcpvR/W1DfRT9SHFT/bCf9ixsjB2HlZGo
uxPJowwqmMgHd755ZzPDUM9YDgLI1yXdcYshObv3Wq537JAxnZJCGRK4Y8SwrMSh
8WRxlaM0AGWXiJFIDD4bQPIdnF3X8w0cGWE5Otkb8mMHOT+rFTVlDODwm1zF6oIG
PTwfVrpiZBwiUtfJol1exr/MzSPyGoJnYs3cRf2E3O+D1LbcR8w0LbjGuUy38Piz
ZO/vCeyJ3JZC5kE8nD+XBA4idwzh0BKEfH9t+WchQ3Up9rxyzLyQamoqt5Xby4pY
=xkM3
-----END PGP PUBLIC KEY BLOCK-----
```
9 changes: 9 additions & 0 deletions ethereum/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.sol]
indent_style = space
indent_size = 4
1 change: 1 addition & 0 deletions ethereum/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.18.0
16 changes: 16 additions & 0 deletions ethereum/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"parser": "solidity-parse",
"printWidth": 120,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
}
]
}
21 changes: 15 additions & 6 deletions ethereum/.solhint.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{
"extends": "solhint:default",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"no-inline-assembly": false
}
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": ["error"],
"func-visibility": ["error", { "ignoreConstructors": true }],
"compiler-version": ["error", ">=0.8.0"],
"max-line-length": ["error", 120],
"var-name-mixedcase": "off",
"func-name-mixedcase": "off",
"no-inline-assembly": "off",
"custom-errors": "off",
"no-global-import": "off",
"no-complex-fallback": "off",
"immutable-vars-naming": ["warn", { "immutablesAsConstants": false }]
}
}
7 changes: 7 additions & 0 deletions ethereum/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"nomicfoundation.hardhat-solidity"
]
}
6 changes: 6 additions & 0 deletions ethereum/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"prettier.documentSelectors": ["**/*.sol"],
"solidity.formatter": "prettier"
}
55 changes: 24 additions & 31 deletions ethereum/contracts/bridge/L1ERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, AllowListed, ReentrancyGua
/// @notice At the time of the function call, it is not yet deployed in L2, but knowledge of its address
/// @notice is necessary for determining L2 token address by L1 address, see `l2TokenAddress(address)` function
/// @param _governor Address which can change L2 token implementation and upgrade the bridge
/// @param _deployBridgeImplementationFee How much of the sent value should be allocated to deploying the L2 bridge implementation
/// @param _deployBridgeImplementationFee How much of the sent value should be allocated to deploying the L2 bridge
/// implementation
/// @param _deployBridgeProxyFee How much of the sent value should be allocated to deploying the L2 bridge proxy
function initialize(
bytes[] calldata _factoryDeps,
Expand Down Expand Up @@ -123,7 +124,8 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, AllowListed, ReentrancyGua
_deployBridgeProxyFee,
l2BridgeProxyBytecodeHash,
l2BridgeProxyConstructorData,
new bytes[](0) // No factory deps are needed for L2 bridge proxy, because it is already passed in previous step
// No factory deps are needed for L2 bridge proxy, because it is already passed in previous step
new bytes[](0)
);
}

Expand All @@ -136,7 +138,8 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, AllowListed, ReentrancyGua
/// @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` and `senderCanCallFunction` modifiers, because the inner method does.
/// NOTE: the function doesn't use `nonreentrant` and `senderCanCallFunction` modifiers, because the inner
/// method does.
function deposit(
address _l2Receiver,
address _l1Token,
Expand All @@ -156,14 +159,18 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, AllowListed, ReentrancyGua
/// @param _l2TxGasPerPubdataByte The gasPerPubdataByteLimit to be used in the corresponding L2 transaction
/// @param _refundRecipient The address on L2 that will receive the refund for the transaction.
/// @dev If the L2 deposit finalization transaction fails, the `_refundRecipient` will receive the `_l2Value`.
/// Please note, the contract may change the refund recipient's address to eliminate sending funds to addresses out of control.
/// Please note, the contract may change the refund recipient's address to eliminate sending funds to addresses
/// out of control.
/// - If `_refundRecipient` is a contract on L1, the refund will be sent to the aliased `_refundRecipient`.
/// - If `_refundRecipient` is set to `address(0)` and the sender has NO deployed bytecode on L1, the refund will be sent to the `msg.sender` address.
/// - If `_refundRecipient` is set to `address(0)` and the sender has deployed bytecode on L1, the refund will be sent to the aliased `msg.sender` address.
/// @dev The address aliasing of L1 contracts as refund recipient on L2 is necessary to guarantee that the funds are controllable through the Mailbox,
/// since the Mailbox applies address aliasing to the from address for the L2 tx if the L1 msg.sender is a contract.
/// Without address aliasing for L1 contracts as refund recipients they would not be able to make proper L2 tx requests
/// through the Mailbox to use or withdraw the funds from L2, and the funds would be lost.
/// - If `_refundRecipient` is set to `address(0)` and the sender has NO deployed bytecode on L1, the refund will
/// be sent to the `msg.sender` address.
/// - If `_refundRecipient` is set to `address(0)` and the sender has deployed bytecode on L1, the refund will be
/// sent to the aliased `msg.sender` address.
/// @dev The address aliasing of L1 contracts as refund recipient on L2 is necessary to guarantee that the funds
/// are controllable through the Mailbox, since the Mailbox applies address aliasing to the from address for the
/// L2 tx if the L1 msg.sender is a contract. Without address aliasing for L1 contracts as refund recipients they
/// would not be able to make proper L2 tx requests through the Mailbox to use or withdraw the funds from L2, and
/// the funds would be lost.
/// @return l2TxHash The L2 transaction hash of deposit finalization
function deposit(
address _l2Receiver,
Expand Down Expand Up @@ -205,11 +212,7 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, AllowListed, ReentrancyGua

/// @dev Transfers tokens from the depositor address to the smart contract address
/// @return The difference between the contract balance before and after the transferring of funds
function _depositFunds(
address _from,
IERC20 _token,
uint256 _amount
) internal returns (uint256) {
function _depositFunds(address _from, IERC20 _token, uint256 _amount) internal returns (uint256) {
uint256 balanceBefore = _token.balanceOf(address(this));
_token.safeTransferFrom(_from, address(this), _amount);
uint256 balanceAfter = _token.balanceOf(address(this));
Expand Down Expand Up @@ -316,17 +319,12 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, AllowListed, ReentrancyGua
}

/// @dev Decode the withdraw message that came from L2
function _parseL2WithdrawalMessage(bytes memory _l2ToL1message)
internal
pure
returns (
address l1Receiver,
address l1Token,
uint256 amount
)
{
function _parseL2WithdrawalMessage(
bytes memory _l2ToL1message
) internal pure returns (address l1Receiver, address l1Token, uint256 amount) {
// Check that the message length is correct.
// It should be equal to the length of the function signature + address + address + uint256 = 4 + 20 + 20 + 32 = 76 (bytes).
// It should be equal to the length of the function signature + address + address + uint256 = 4 + 20 + 20 + 32 =
// 76 (bytes).
require(_l2ToL1message.length == 76, "kk");

(uint32 functionSignature, uint256 offset) = UnsafeBytes.readUint32(_l2ToL1message, 0);
Expand All @@ -338,12 +336,7 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, AllowListed, ReentrancyGua
}

/// @dev Verify the deposit limit is reached to its cap or not
function _verifyDepositLimit(
address _l1Token,
address _depositor,
uint256 _amount,
bool _claiming
) internal {
function _verifyDepositLimit(address _l1Token, address _depositor, uint256 _amount, bool _claiming) internal {
IAllowList.Deposit memory limitData = IAllowList(allowList).getTokenDepositLimitData(_l1Token);
if (!limitData.depositLimitation) return; // no deposit limitation is placed for this token

Expand Down
Loading

0 comments on commit c2dc75a

Please sign in to comment.