forked from matter-labs/era-contracts
-
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.
* initial commit * Refactor deposit validation logic in L1ERC20Bridge.sol * fix Should not allow depositing zero amount * fix l1_erc20_bridge tests * Refactor withdrawal handling in MailboxFacet * fixes * fix deployL2 * fix l2 weth init * fix weth bridge tests * Restore preprocessor conditional --------- Co-authored-by: Jmunoz <[email protected]>
- Loading branch information
1 parent
79f4c20
commit f4f28c8
Showing
13 changed files
with
117 additions
and
53 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
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 |
---|---|---|
|
@@ -22,6 +22,8 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol | |
// While formally the following import is not used, it is needed to inherit documentation from it | ||
import {IBase} from "../interfaces/IBase.sol"; | ||
|
||
bool constant NATIVE_ERC20 = $(NATIVE_ERC20); | ||
|
||
/// @title zkSync Mailbox contract providing interfaces for L1 <-> L2 interaction. | ||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
|
@@ -173,8 +175,7 @@ contract MailboxFacet is Base, IMailbox { | |
bytes calldata _message, | ||
bytes32[] calldata _merkleProof | ||
) external nonReentrant { | ||
// #def TOKEN_TYPE 'ERC20' | ||
// #if TOKEN_TYPE == 'ETH' | ||
// #if NATIVE_ERC20 == false | ||
require(!s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex], "jj"); | ||
|
||
L2Message memory l2ToL1Message = L2Message({ | ||
|
@@ -183,16 +184,16 @@ contract MailboxFacet is Base, IMailbox { | |
data: _message | ||
}); | ||
|
||
(address _l1WithdrawReceiver, address _t, uint256 _amount) = _parseL2WithdrawalMessage(_message); | ||
(address _l1WithdrawReceiver, uint256 _amount) = _parseL2WithdrawalMessage(_message); | ||
{ | ||
bool proofValid = proveL2MessageInclusion(_l2BatchNumber, _l2MessageIndex, l2ToL1Message, _merkleProof); | ||
require(proofValid, "pi"); // Failed to verify that withdrawal was actually initialized on L2 | ||
} | ||
s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex] = true; | ||
_withdrawFunds(_l1WithdrawReceiver, _amount); | ||
|
||
emit EthWithdrawalFinalized(_l1WithdrawReceiver, _amount); | ||
// #elif TOKEN_TYPE == 'ERC20' | ||
// #elif NATIVE_ERC20 == true | ||
require(!s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex], "pw"); | ||
|
||
L2Message memory l2ToL1Message = L2Message({ | ||
|
@@ -230,10 +231,10 @@ contract MailboxFacet is Base, IMailbox { | |
) external payable nonReentrant returns (bytes32 canonicalTxHash) { | ||
// Change the sender address if it is a smart contract to prevent address collision between L1 and L2. | ||
// Please note, currently zkSync address derivation is different from Ethereum one, but it may be changed in the future. | ||
// address sender = msg.sender; | ||
// if (sender != tx.origin) { | ||
// sender = AddressAliasHelper.applyL1ToL2Alias(msg.sender); | ||
// } | ||
address sender = msg.sender; | ||
if (sender != tx.origin) { | ||
sender = AddressAliasHelper.applyL1ToL2Alias(msg.sender); | ||
} | ||
|
||
// Enforcing that `_l2GasPerPubdataByteLimit` equals to a certain constant number. This is needed | ||
// to ensure that users do not get used to using "exotic" numbers for _l2GasPerPubdataByteLimit, e.g. 1-2, etc. | ||
|
@@ -243,7 +244,7 @@ contract MailboxFacet is Base, IMailbox { | |
require(_l2GasPerPubdataByteLimit == REQUIRED_L2_GAS_PRICE_PER_PUBDATA, "qp"); | ||
|
||
canonicalTxHash = _requestL2Transaction( | ||
msg.sender, | ||
sender, | ||
_contractL2, | ||
_l2Value, | ||
_amount, | ||
|
@@ -273,12 +274,15 @@ contract MailboxFacet is Base, IMailbox { | |
// Here we manually assign fields for the struct to prevent "stack too deep" error | ||
WritePriorityOpParams memory params; | ||
|
||
uint256 amount = _amount != 0 ? _amount : msg.value; | ||
// uint256 amount = msg.value; | ||
|
||
// Checking that the user provided enough ether to pay for the transaction. | ||
// Using a new scope to prevent "stack too deep" error | ||
{ | ||
params.l2GasPrice = _isFree ? 0 : _deriveL2GasPrice(tx.gasprice, _l2GasPerPubdataByteLimit); | ||
uint256 baseCost = params.l2GasPrice * _l2GasLimit; | ||
require(_amount >= baseCost + _l2Value, "mv"); // The `msg.value` doesn't cover the transaction cost | ||
require(amount >= baseCost + _l2Value, "mv"); // The `amount` doesn't cover the transaction cost | ||
} | ||
|
||
// If the `_refundRecipient` is not provided, we use the `_sender` as the recipient. | ||
|
@@ -288,22 +292,25 @@ contract MailboxFacet is Base, IMailbox { | |
refundRecipient = AddressAliasHelper.applyL1ToL2Alias(refundRecipient); | ||
} | ||
|
||
// The address of the token that is used in the L2 as native. | ||
address nativeTokenAddress = address($(L1_NATIVE_TOKEN_ADDRESS)); | ||
// Check balance and allowance. | ||
require(IERC20(nativeTokenAddress).balanceOf(tx.origin) >= _amount, "Not enough balance"); | ||
require(IERC20(nativeTokenAddress).allowance(tx.origin, address(this)) >= _amount, "Not enough allowance"); | ||
// Check if we are operating with native tokens. | ||
if (_amount != 0) { | ||
// The address of the token that is used in the L2 as native. | ||
address nativeTokenAddress = address($(L1_NATIVE_TOKEN_ADDRESS)); | ||
// Check balance and allowance. | ||
require(IERC20(nativeTokenAddress).balanceOf(tx.origin) >= amount, "Not enough balance"); | ||
require(IERC20(nativeTokenAddress).allowance(tx.origin, address(this)) >= amount, "Not enough allowance"); | ||
|
||
// Transfer tokens to the contract. | ||
IERC20(nativeTokenAddress).safeTransferFrom(tx.origin, address(this), _amount); | ||
// Transfer tokens to the contract. | ||
IERC20(nativeTokenAddress).safeTransferFrom(tx.origin, address(this), amount); | ||
} | ||
|
||
params.sender = _sender; | ||
params.txId = s.priorityQueue.getTotalPriorityTxs(); | ||
params.l2Value = _l2Value; | ||
params.contractAddressL2 = _contractAddressL2; | ||
params.expirationTimestamp = uint64(block.timestamp + PRIORITY_EXPIRATION); | ||
params.l2GasLimit = _l2GasLimit; | ||
params.valueToMint = _amount; | ||
params.valueToMint = amount; | ||
params.l2GasPricePerPubdata = _l2GasPerPubdataByteLimit; | ||
params.refundRecipient = refundRecipient; | ||
|
||
|
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
Oops, something went wrong.