Skip to content

Commit

Permalink
Restore preprocessor conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchatruc committed Feb 5, 2024
1 parent 37d8b56 commit c1fac02
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 36 deletions.
74 changes: 38 additions & 36 deletions l1-contracts/contracts/zksync/facets/Mailbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -173,47 +175,47 @@ contract MailboxFacet is Base, IMailbox {
bytes calldata _message,
bytes32[] calldata _merkleProof
) external nonReentrant {
if (true) { // TOKEN_TYPE == 'ETH'
require(!s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex], "jj");

L2Message memory l2ToL1Message = L2Message({
txNumberInBatch: _l2TxNumberInBatch,
sender: L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR,
data: _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);
// #if NATIVE_ERC20 == false
require(!s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex], "jj");

emit EthWithdrawalFinalized(_l1WithdrawReceiver, _amount);
} else if (true) { // TOKEN_TYPE == 'ERC20'
require(!s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex], "pw");
L2Message memory l2ToL1Message = L2Message({
txNumberInBatch: _l2TxNumberInBatch,
sender: L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR,
data: _message
});

L2Message memory l2ToL1Message = L2Message({
txNumberInBatch: _l2TxNumberInBatch,
sender: L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR,
data: _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 NATIVE_ERC20 == true
require(!s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex], "pw");

L2Message memory l2ToL1Message = L2Message({
txNumberInBatch: _l2TxNumberInBatch,
sender: L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR,
data: _message
});

(address l1Receiver, uint256 amount) = _parseL2WithdrawalMessage(l2ToL1Message.data);
// Preventing the stack too deep error
{
bool success = proveL2MessageInclusion(_l2BatchNumber, _l2MessageIndex, l2ToL1Message, _merkleProof);
require(success, "nq");
}
(address l1Receiver, uint256 amount) = _parseL2WithdrawalMessage(l2ToL1Message.data);
// Preventing the stack too deep error
{
bool success = proveL2MessageInclusion(_l2BatchNumber, _l2MessageIndex, l2ToL1Message, _merkleProof);
require(success, "nq");
}

s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex] = true;
// Withdraw funds
address l1Token = $(NATIVE_ERC20_ADDRESS);
IERC20(l1Token).safeTransfer(l1Receiver, amount);
s.isEthWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex] = true;
// Withdraw funds
address l1Token = $(NATIVE_ERC20_ADDRESS);
IERC20(l1Token).safeTransfer(l1Receiver, amount);

emit WithdrawalFinalized(l1Receiver, amount);
}
emit WithdrawalFinalized(l1Receiver, amount);
// #endif
}

/// @inheritdoc IMailbox
Expand Down
1 change: 1 addition & 0 deletions l1-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default {
}

return {
NATIVE_ERC20: process.env.NATIVE_ERC20,
NATIVE_ERC20_ADDRESS: address,
...systemParams,
...defs,
Expand Down

0 comments on commit c1fac02

Please sign in to comment.