Skip to content

Commit

Permalink
Adding doc comments to the chain contracts (matter-labs#530)
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <deniallugo@gmail.com>
Co-authored-by: Lyova Potyomkin <lyova.potyomkin@gmail.com>
Co-authored-by: kelemeno <kl@matterlabs.dev>
Co-authored-by: Stanislav Bezkorovainyi <stanislavbezkor@gmail.com>
Co-authored-by: Raid Ateir <ra@matterlabs.dev>
Co-authored-by: kelemeno <34402761+kelemeno@users.noreply.github.com>
Co-authored-by: Jmunoz <juanmunoz890@gmail.com>
Co-authored-by: Bence Haromi <bence.haromi@gmail.com>
Co-authored-by: Danil <deniallugo@gmail.com>
  • Loading branch information
9 people authored and Yberjon committed Aug 12, 2024
1 parent c15005f commit bdcf146
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
21 changes: 19 additions & 2 deletions l1-contracts/contracts/bridge/L1SharedBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade
}

/// @dev This sets the first post upgrade batch for era, used to check old withdrawals
/// @param _eraLegacyBridgeLastDepositBatch The the zkSync Era batch number that processes the last deposit tx initiated by the legacy bridge
/// @param _eraLegacyBridgeLastDepositBatch The the zkSync Era batch number that processes the last deposit tx initiated by the legacy bridge
/// @param _eraLegacyBridgeLastDepositTxNumber The tx number in the _eraLegacyBridgeLastDepositBatch of the last deposit tx initiated by the legacy bridge
function setEraLegacyBridgeLastDepositTime(
uint256 _eraLegacyBridgeLastDepositBatch,
Expand All @@ -168,7 +168,10 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade
eraLegacyBridgeLastDepositTxNumber = _eraLegacyBridgeLastDepositTxNumber;
}

/// @dev transfer tokens from legacy erc20 bridge or mailbox and set chainBalance as part of migration process
/// @dev Transfer tokens from legacy erc20 bridge or mailbox and set chainBalance as part of migration process.
/// @param _token The address of token to be transferred (address(1) for ether and contract address for ERC20).
/// @param _target The hyperchain or bridge contract address from where to transfer funds.
/// @param _targetChainId The chain ID of the corresponding hyperchain.
function transferFundsFromLegacy(address _token, address _target, uint256 _targetChainId) external onlySelf {
if (_token == ETH_TOKEN_ADDRESS) {
uint256 balanceBefore = address(this).balance;
Expand Down Expand Up @@ -204,6 +207,8 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade
}
}

/// @dev Accepts ether only from the hyperchain associated with the specified chain ID.
/// @param _chainId The chain ID corresponding to the hyperchain allowed to send ether.
function receiveEth(uint256 _chainId) external payable {
require(BRIDGE_HUB.getHyperchain(_chainId) == msg.sender, "receiveEth not state transition");
}
Expand All @@ -215,6 +220,10 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade

/// @notice Allows bridgehub to acquire mintValue for L1->L2 transactions.
/// @dev If the corresponding L2 transaction fails, refunds are issued to a refund recipient on L2.
/// @param _chainId The chain ID of the hyperchain to which deposit.
/// @param _prevMsgSender The `msg.sender` address from the external call that initiated current one.
/// @param _l1Token The L1 token address which is deposited.
/// @param _amount The total amount of tokens to be bridged.
function bridgehubDepositBaseToken(
uint256 _chainId,
address _prevMsgSender,
Expand Down Expand Up @@ -250,6 +259,10 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade
}

/// @notice Initiates a deposit transaction within Bridgehub, used by `requestL2TransactionTwoBridges`.
/// @param _chainId The chain ID of the hyperchain to which deposit.
/// @param _prevMsgSender The `msg.sender` address from the external call that initiated current one.
/// @param _l2Value The L2 `msg.value` from the L1 -> L2 deposit transaction.
/// @param _data The calldata for the second bridge deposit.
function bridgehubDeposit(
uint256 _chainId,
address _prevMsgSender,
Expand Down Expand Up @@ -315,6 +328,9 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade

/// @notice Confirms the acceptance of a transaction by the Mailbox, as part of the L2 transaction process within Bridgehub.
/// This function is utilized by `requestL2TransactionTwoBridges` to validate the execution of a transaction.
/// @param _chainId The chain ID of the hyperchain to which confirm the deposit.
/// @param _txDataHash The keccak256 hash of abi.encode(msgSender, l1Token, amount)
/// @param _txHash The hash of the L1->L2 transaction to confirm the deposit.
function bridgehubConfirmL2Transaction(
uint256 _chainId,
bytes32 _txDataHash,
Expand Down Expand Up @@ -665,6 +681,7 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade
/// of processing an L2 transaction where tokens would be minted.
/// @dev If the token is bridged for the first time, the L2 token contract will be deployed. Note however, that the
/// newly-deployed token does not support any custom logic, i.e. rebase tokens' functionality is not supported.
/// @param _prevMsgSender The `msg.sender` address from the external call that initiated current one.
/// @param _l2Receiver The account address that should receive funds on L2
/// @param _l1Token The L1 token address which is deposited
/// @param _amount The total amount of tokens to be bridged
Expand Down
26 changes: 26 additions & 0 deletions l1-contracts/contracts/bridgehub/Bridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import {ETH_TOKEN_ADDRESS, TWO_BRIDGES_MAGIC_VALUE, BRIDGEHUB_MIN_SECOND_BRIDGE_
import {BridgehubL2TransactionRequest, L2Message, L2Log, TxStatus} from "../common/Messaging.sol";
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol";

/// @author Matter Labs
/// @custom:security-contact security@matterlabs.dev
/// @dev The Bridgehub contract serves as the primary entry point for L1<->L2 communication,
/// facilitating interactions between end user and bridges.
/// It also manages state transition managers, base tokens, and chain registrations.
contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, PausableUpgradeable {
/// @notice all the ether is held by the weth bridge
IL1SharedBridge public sharedBridge;
Expand Down Expand Up @@ -155,6 +160,12 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
//// Mailbox forwarder

/// @notice forwards function call to Mailbox based on ChainId
/// @param _chainId The chain ID of the hyperchain where to prove L2 message inclusion.
/// @param _batchNumber The executed L2 batch number in which the message appeared
/// @param _index The position in the L2 logs Merkle tree of the l2Log that was sent with the message
/// @param _message Information about the sent message: sender address, the message itself, tx index in the L2 batch where the message was sent
/// @param _proof Merkle proof for inclusion of L2 log that was sent with the message
/// @return Whether the proof is valid
function proveL2MessageInclusion(
uint256 _chainId,
uint256 _batchNumber,
Expand All @@ -167,6 +178,12 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
}

/// @notice forwards function call to Mailbox based on ChainId
/// @param _chainId The chain ID of the hyperchain where to prove L2 log inclusion.
/// @param _batchNumber The executed L2 batch number in which the log appeared
/// @param _index The position of the l2log in the L2 logs Merkle tree
/// @param _log Information about the sent log
/// @param _proof Merkle proof for inclusion of the L2 log
/// @return Whether the proof is correct and L2 log is included in batch
function proveL2LogInclusion(
uint256 _chainId,
uint256 _batchNumber,
Expand All @@ -179,6 +196,15 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
}

/// @notice forwards function call to Mailbox based on ChainId
/// @param _chainId The chain ID of the hyperchain where to prove L1->L2 tx status.
/// @param _l2TxHash The L2 canonical transaction hash
/// @param _l2BatchNumber The L2 batch number where the transaction was processed
/// @param _l2MessageIndex The position in the L2 logs Merkle tree of the l2Log that was sent with the message
/// @param _l2TxNumberInBatch The L2 transaction number in the batch, in which the log was sent
/// @param _merkleProof The Merkle proof of the processing L1 -> L2 transaction
/// @param _status The execution status of the L1 -> L2 transaction (true - success & 0 - fail)
/// @return Whether the proof is correct and the transaction was actually executed with provided status
/// NOTE: It may return `false` for incorrect proof, but it doesn't mean that the L1 -> L2 transaction has an opposite status!
function proveL1ToL2TransactionStatus(
uint256 _chainId,
bytes32 _l2TxHash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract MailboxFacet is ZkSyncHyperchainBase, IMailbox {
string public constant override getName = "MailboxFacet";

/// @dev Era's chainID
uint256 public immutable ERA_CHAIN_ID;
uint256 internal immutable ERA_CHAIN_ID;

constructor(uint256 _eraChainId) {
ERA_CHAIN_ID = _eraChainId;
Expand Down
2 changes: 2 additions & 0 deletions l2-contracts/contracts/bridge/L2SharedBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ contract L2SharedBridge is IL2SharedBridge, Initializable {

/// @dev Contract is expected to be used as proxy implementation.
/// @dev Disable the initialization to prevent Parity hack.
uint256 public immutable ERA_CHAIN_ID;

constructor(uint256 _eraChainId) {
ERA_CHAIN_ID = _eraChainId;
_disableInitializers();
Expand Down

0 comments on commit bdcf146

Please sign in to comment.