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

Adding doc comments to the chain contracts #530

Merged
merged 150 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
587fc6f
Use Governance contract as STM owner
ly0va Apr 2, 2024
56cfe4b
Fix deploy script with undefined chainId
ly0va Apr 3, 2024
08fcdc3
updating hyperchain migration tests
kelemeno Mar 21, 2024
fed442f
updating hyperchain migration tests
kelemeno Mar 21, 2024
a975413
modifying hyperchain upgrade
kelemeno Mar 24, 2024
1cc2c80
creating script for hyperchain upgrade
kelemeno Mar 25, 2024
5eaf3fa
updated upgrade scripts
kelemeno Mar 25, 2024
89ebe8e
zk fmt
kelemeno Mar 25, 2024
5cf9582
contracts era chain id fix
kelemeno Mar 26, 2024
34a9cd5
zk fmt and linting
kelemeno Mar 26, 2024
5a32908
small fix in deploy script
kelemeno Mar 26, 2024
a21571b
genesis protocol version from latest p v
kelemeno Mar 28, 2024
30f8956
updated upgrade tests
kelemeno Apr 3, 2024
4befd8a
Ownable2StepUpgradeable
kelemeno Apr 3, 2024
c6be4c7
fixed typo
kelemeno Apr 1, 2024
445bcf7
fixed "changeFeeParams" function
kelemeno Apr 1, 2024
cff36f9
setValidium mode based on storedBatchHashes
kelemeno Apr 1, 2024
8f4c5b0
Fix PR review
vladbochok Apr 1, 2024
ee5ca89
fixed currentPendingAdmin log error
kelemeno Apr 1, 2024
021b1c0
new events
kelemeno Apr 1, 2024
38147a6
gas cost fixes
kelemeno Apr 2, 2024
ee7bd5a
zk lint
kelemeno Apr 2, 2024
db1130f
changed STM -> DP functions
kelemeno Apr 1, 2024
78d4951
zk fmt
kelemeno Apr 1, 2024
622a801
Address review
vladbochok Apr 1, 2024
df9f325
Fix review
vladbochok Apr 1, 2024
488d15b
added onlyOwner
kelemeno Apr 2, 2024
bc02bed
validation issues, OZ L04
kelemeno Apr 1, 2024
0b93956
zk fmt
kelemeno Apr 1, 2024
8a5de19
fixed tests
kelemeno Apr 1, 2024
207d195
Address review
vladbochok Apr 1, 2024
ceb100f
fixed require statement and error message
kelemeno Apr 1, 2024
094f57f
lint
kelemeno Apr 1, 2024
bd9e94d
Fix L-06
vladbochok Apr 1, 2024
a5dfc6a
add extra comments in STM
kelemeno Apr 2, 2024
bbbe9e9
Fix N-02
vladbochok Apr 1, 2024
24c8be7
lints
vladbochok Apr 1, 2024
f360d0e
Fix test
vladbochok Apr 1, 2024
af562bd
Update l1-contracts/contracts/state-transition/StateTransitionManager…
StanislavBreadless Apr 1, 2024
3f92673
Fix N-03
vladbochok Apr 1, 2024
ca34c4b
remove redundancy
StanislavBreadless Apr 1, 2024
ca524ce
fix lint
StanislavBreadless Apr 1, 2024
8cd5184
fix casting bridges
StanislavBreadless Apr 1, 2024
3998cad
added new doc strings
kelemeno Apr 2, 2024
88e3c7c
zk lint
kelemeno Apr 2, 2024
60cf175
fix typographical errors
Apr 1, 2024
39abd6c
add named parameters and improve descriptions
Apr 1, 2024
b2ea1b5
zk lint
kelemeno Apr 1, 2024
72a49c6
add indexed params for validator timelock events
Apr 1, 2024
882e4e7
Fix tests
vladbochok Apr 1, 2024
42bacf9
renaming n09
kelemeno Apr 1, 2024
ced6472
some naming issues
kelemeno Apr 3, 2024
a1bd4cc
removed payable
kelemeno Apr 1, 2024
0c3e2d2
removed payable from interface
kelemeno Apr 1, 2024
4dc74b8
renamed StateTransition to Hyperchain
kelemeno Apr 1, 2024
4ba6bcf
renaming revert messages
kelemeno Apr 3, 2024
46f85d4
Update l1-contracts/contracts/state-transition/StateTransitionManager…
kelemeno Apr 3, 2024
d66e55f
zk fmt
vladbochok Apr 1, 2024
2194747
fixing tests
kelemeno Apr 3, 2024
15293e4
added new SharedBridgeTest file
kelemeno Apr 3, 2024
a19cd47
move nonce to correct location
juan518munoz Apr 5, 2024
dc4d1b6
Merge pull request #319 from lambdaclass/without-1.5.0-fix-nonce
kelemeno Apr 5, 2024
6aef3b7
small renaming
kelemeno Apr 8, 2024
3be4efc
missing import added back
benceharomi Apr 8, 2024
efb9af3
move eraSetFirstUpgradeBatch to its own function
kelemeno Apr 8, 2024
b7b61ef
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 8, 2024
a30ecb6
fix test
kelemeno Apr 8, 2024
b5d7fc5
merging differences, tests
kelemeno Apr 8, 2024
98ee7e5
kelemeno -> zksync-sdk
ly0va Apr 8, 2024
5eb45d2
Fix utils
ly0va Apr 8, 2024
38c1237
Fix config path
ly0va Apr 8, 2024
27e3ba8
fix(deploy-test-process): CONTRACTS_ERA_CHAIN_ID set to 270
benceharomi Apr 8, 2024
7de6499
deploy-preimages fix: zksync-web3 added back
benceharomi Apr 8, 2024
d70e5e0
small chainId changes
kelemeno Apr 8, 2024
97f2a83
config change back
kelemeno Apr 8, 2024
964c1d0
zk fmt
kelemeno Apr 8, 2024
affa83d
linting
kelemeno Apr 9, 2024
45ee4ae
small import change
kelemeno Apr 9, 2024
4844258
zk fmt
kelemeno Apr 9, 2024
d023451
test fix
kelemeno Apr 9, 2024
bc40ba2
zk lint
kelemeno Apr 9, 2024
742c131
renaming file
kelemeno Apr 9, 2024
bf2a357
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 9, 2024
e78c5c3
small fixes
kelemeno Apr 9, 2024
76cd777
l2-contracts deploy utils
kelemeno Apr 9, 2024
17daf4a
zk lint
kelemeno Apr 9, 2024
8c4e10a
system contract fix attempt 1
kelemeno Apr 9, 2024
434ef23
zk fmt
kelemeno Apr 9, 2024
f4e562a
system contract fix attempt 2
kelemeno Apr 9, 2024
2d54bcd
added output
kelemeno Apr 9, 2024
91b657d
package.json attempt
kelemeno Apr 9, 2024
9026685
attempt 4
kelemeno Apr 9, 2024
52d2d46
linting
kelemeno Apr 9, 2024
6770c0b
yarn update
kelemeno Apr 9, 2024
f403e23
small fix
kelemeno Apr 9, 2024
ee2717b
fixes based for Bence's comments
kelemeno Apr 9, 2024
c43cf97
small contract fixes, added extra script
kelemeno Apr 9, 2024
96c9814
Vlad and Stas issues
kelemeno Apr 10, 2024
9a1d6a1
state transition hyperchain renaming
kelemeno Apr 10, 2024
1b42052
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 10, 2024
1fd4cd8
oz upgradable contracts submodule
kelemeno Apr 10, 2024
6c82491
attempt remove from foundry.toml
kelemeno Apr 10, 2024
ae16bd5
address alias helper cleanup
kelemeno Apr 10, 2024
2e21950
Merge branch 'dev' into kl/without-1.5.0-merge-dev
Deniallugo Apr 10, 2024
27fc259
forge install: openzeppelin-contracts-upgradeable
Deniallugo Apr 10, 2024
f33e767
Fix foundry scripts
Deniallugo Apr 10, 2024
c706d00
slither
kelemeno Apr 10, 2024
4b3ea16
slither
kelemeno Apr 10, 2024
95e5571
Merge branch 'dev' into kl/without-1.5.0-merge-dev
Deniallugo Apr 11, 2024
032427b
upgrade fix
kelemeno Apr 11, 2024
6ca20c6
spellcheck
kelemeno Apr 12, 2024
40d0f60
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 12, 2024
c88cb6f
small contract fixes
kelemeno Apr 12, 2024
80d3067
zk fmt && zk lint
kelemeno Apr 12, 2024
6a9a0d0
fix C4 issue related to claimFailedDeposits
kelemeno Apr 12, 2024
da97cae
fixes, linting
kelemeno Apr 12, 2024
dab2a1f
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 12, 2024
d32f4a3
cleaned up hyperchain-upgrade test a bit,
kelemeno Apr 12, 2024
8656a58
rename and add to interface
kelemeno Apr 12, 2024
a2f0167
fixed comparison error
kelemeno Apr 12, 2024
6f8ae38
better name
kelemeno Apr 12, 2024
f168e54
changed the names a bit
kelemeno Apr 12, 2024
a60710d
finalizeWithdrawal check eraPostUpgradeFirstBatch
kelemeno Apr 12, 2024
53a0a21
last deposit time edge case
kelemeno Apr 12, 2024
5e033da
removed wrong check (tx number = 0 is allowed)
kelemeno Apr 12, 2024
857eada
separate eth and token withdrawal batch number
kelemeno Apr 13, 2024
95da499
cleanup
kelemeno Apr 13, 2024
76acbf5
more migration testing
kelemeno Apr 15, 2024
a997ae6
small typo fix
kelemeno Apr 16, 2024
77d1cc8
tokenProxyBytecodeHash now only
kelemeno Apr 16, 2024
77ec2bb
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 16, 2024
74311c2
extra comments
kelemeno Apr 16, 2024
cfa3307
Bunch of improvements
vladbochok Apr 16, 2024
435d2a8
Add pause feature and function for getting all hyperchains
vladbochok Apr 17, 2024
f2c06cf
Merge branch 'kl/without-1.5.0-merge-dev' into vb-hyper-improvements-2
vladbochok Apr 17, 2024
eb7a5b8
Change permissions
vladbochok Apr 17, 2024
42c8f04
Fix tests + add function for getting chain IDS
vladbochok Apr 17, 2024
5880110
Change constants
vladbochok Apr 17, 2024
7850f13
Update test config
vladbochok Apr 17, 2024
19a33d6
Address review
vladbochok Apr 17, 2024
af75513
hyperchain -> getHyperchain
vladbochok Apr 17, 2024
8b1aa76
provide constructor params
StanislavBreadless Apr 17, 2024
0fc6fa8
sync with dev
StanislavBreadless Apr 19, 2024
37e0199
Fix audit issue N-01 (#430)
vladbochok Jun 12, 2024
c68a7e5
Fix audit issue N-02 (#431)
vladbochok Jun 12, 2024
2f42850
Fix audit issue L-01 (#432)
vladbochok Jun 12, 2024
8532ada
Fix audit issue L-02 (#433)
vladbochok Jun 12, 2024
4abad56
Merge branch 'dev' into oz-hyper-improvements-audit
vladbochok Jun 12, 2024
372d84d
Make ERA_CHAIN_ID public
vladbochok Jun 12, 2024
dfc2576
Merge branch 'dev' into oz-hyper-improvements-audit
vladbochok Jun 18, 2024
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
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;
vladbochok marked this conversation as resolved.
Show resolved Hide resolved

constructor(uint256 _eraChainId) {
ERA_CHAIN_ID = _eraChainId;
Expand Down
4 changes: 2 additions & 2 deletions l2-contracts/contracts/bridge/L2SharedBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ contract L2SharedBridge is IL2SharedBridge, Initializable {
/// This is non-zero only on Era, and should not be renamed for backward compatibility with the SDKs.
address public override l1Bridge;

uint256 public immutable ERA_CHAIN_ID;

/// @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
Loading