Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(l1-contracts): Migrate L1 Contracts to Custom Errors #477

Merged
merged 23 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codespell/wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ue
tha
bu
crate
DNE
2 changes: 2 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extend-exclude = [
"/l1-contracts/out/",
"/l1-contracts/node_modules/",
"/l1-contracts/artifacts",
"/l1-contracts-foundry/lib/",
"/l2-contracts/artifacts-zk",
"/l2-contracts/cache-zk",
"/l2-contracts/typechain",
Expand All @@ -22,3 +23,4 @@ extend-exclude = [
# Don't correct the surname "Teh"
FOT = "FOT"
ue = "ue"
DNE = "DNE"
27 changes: 20 additions & 7 deletions l1-contracts/contracts/bridge/L1ERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

pragma solidity 0.8.24;

// solhint-disable gas-custom-errors

import {IERC20} from "@openzeppelin/contracts-v4/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts-v4/token/ERC20/utils/SafeERC20.sol";

Expand All @@ -13,6 +11,8 @@ import {IL1SharedBridge} from "./interfaces/IL1SharedBridge.sol";
import {L2ContractHelper} from "../common/libraries/L2ContractHelper.sol";
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";

import {Unauthorized, EmptyDeposit, ValueMismatch, WithdrawalAlreadyFinalized} from "../common/L1ContractErrors.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
/// @notice Smart contract that allows depositing ERC20 tokens from Ethereum to hyperchains
Expand Down Expand Up @@ -67,7 +67,9 @@ contract L1ERC20Bridge is IL1ERC20Bridge, ReentrancyGuard {

/// @dev transfer token to shared bridge as part of upgrade
function transferTokenToSharedBridge(address _token) external {
require(msg.sender == address(SHARED_BRIDGE), "Not shared bridge");
if (msg.sender != address(SHARED_BRIDGE)) {
revert Unauthorized(msg.sender);
}
uint256 amount = IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(address(SHARED_BRIDGE), amount);
}
Expand Down Expand Up @@ -150,9 +152,15 @@ contract L1ERC20Bridge is IL1ERC20Bridge, ReentrancyGuard {
uint256 _l2TxGasPerPubdataByte,
address _refundRecipient
) public payable nonReentrant returns (bytes32 l2TxHash) {
require(_amount != 0, "0T"); // empty deposit
// empty deposit
if (_amount == 0) {
revert EmptyDeposit();
}
uint256 amount = _depositFundsToSharedBridge(msg.sender, IERC20(_l1Token), _amount);
require(amount == _amount, "3T"); // The token has non-standard transfer logic
// The token has non-standard transfer logic
if (amount != _amount) {
revert ValueMismatch(_amount, amount);
}

l2TxHash = SHARED_BRIDGE.depositLegacyErc20Bridge{value: msg.value}({
_msgSender: msg.sender,
Expand Down Expand Up @@ -196,7 +204,10 @@ contract L1ERC20Bridge is IL1ERC20Bridge, ReentrancyGuard {
bytes32[] calldata _merkleProof
) external nonReentrant {
uint256 amount = depositAmount[_depositSender][_l1Token][_l2TxHash];
require(amount != 0, "2T"); // empty deposit
// empty deposit
if (amount == 0) {
revert EmptyDeposit();
}
delete depositAmount[_depositSender][_l1Token][_l2TxHash];

SHARED_BRIDGE.claimFailedDepositLegacyErc20Bridge({
Expand Down Expand Up @@ -225,7 +236,9 @@ contract L1ERC20Bridge is IL1ERC20Bridge, ReentrancyGuard {
bytes calldata _message,
bytes32[] calldata _merkleProof
) external nonReentrant {
require(!isWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex], "pw");
if (isWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex]) {
revert WithdrawalAlreadyFinalized();
}
// We don't need to set finalizeWithdrawal here, as we set it in the shared bridge

(address l1Receiver, address l1Token, uint256 amount) = SHARED_BRIDGE.finalizeWithdrawalLegacyErc20Bridge({
Expand Down
Loading
Loading