Skip to content

Conversation

kelemeno
Copy link
Contributor

What ❔

Why ❔

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.

using SafeERC20 for IERC20;

/// @dev Bridgehub smart contract that is used to operate with L2 via asynchronous L2 <-> L1 communication.
address public immutable BRIDGE_HUB;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is BRIDGE_HUB of the address type but nativeTokenVault is not? I think we need to choose one way we do this unless there's a reason not to.

Also, there're a few instances of unnecessary casting of BRIDGE_HUB anyway.

/// @notice A contract that deploys the upgradeable beacon for the bridged standard ERC20 token.
/// @dev Besides separation of concerns, we need it as a separate contract to ensure that L2NativeTokenVaultZKOS
/// does not have to include BridgedStandardERC20 and UpgradeableBeacon and so can fit into the code size limit.
contract UpgradeableBeaconDeployer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this contract in l1-contracts/contracts/bridge/ntv but not in l1-contracts/contracts/bridge like BridgedStandardERC20 is?

Comment on lines +200 to +202
for (uint256 i = 0; i < publicInputsLength; ++i) {
initialHash = uint256(keccak256(abi.encodePacked(initialHash, _publicInputs[i]))) >> 32;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The common loop should be outside of the if condition to eliminate code duplication

Comment on lines +26 to +30
/// @notice Type of verification for FFLONK verifier.
uint256 internal constant FFLONK_VERIFICATION_TYPE = 0;

/// @notice Type of verification for PLONK verifier.
uint256 internal constant PLONK_VERIFICATION_TYPE = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need these types given that ZKsyncOSDualVerifier is a ZKsync OS-specific contract?

Comment on lines +34 to +35
// @notice This is test only verifier (mock), and must be removed before prod.
uint256 internal constant ZKSYNC_OS_MOCK_VERIFICATION_TYPE = 3;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove it as the comment states?

Comment on lines +140 to +141
uint256 verifierType = _verifierType & 255;
uint32 verifierVersion = uint32(verifierType >> 8);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we do it twice, I suggest to separate this encoding/decoding to an internal function

Comment on lines +177 to +187
function _extractZKSyncOSProof(uint256[] calldata _proof) internal pure returns (uint256[] memory result) {
uint256 resultLength = _proof.length - 1 - 1;

// Allocate memory for the new array (_proof.length - 1) since the first element is omitted.
result = new uint256[](resultLength);

// Copy elements starting from index 1 (the second element) of the original array.
assembly {
calldatacopy(add(result, 0x20), add(_proof.offset, 0x40), mul(resultLength, 0x20))
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function duplicates a lot of code from _extractProof. They should be the same function with a flag argument which tells whether it's ZKsync OS or not.

Comment on lines -170 to -172
if (_chainCreationParams.genesisIndexRepeatedStorageChanges == uint64(0)) {
revert GenesisIndexStorageZero();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this check?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, it should only be removed in ZKsync OS specific CTM

/// @param _expirationTimestamp the expiration timestamp for the transaction
function forwardTransactionOnGateway(
uint256 _chainId,
bytes32 _canonicalTxHash,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function should be removed from here, its only L2

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Coverage after merging draft-v30 into draft-v29 will be

80.23%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
contracts/bridge
   BridgeHelper.sol85.71%100%100%85%31, 36, 41
   BridgedStandardERC20.sol82.14%100%92.31%80.28%120–121, 126–127, 139–140, 164, 205, 212, 219, 229–230, 63, 91
   L1ERC20Bridge.sol94%100%100%93.02%189, 208, 270
   L1Nullifier.sol83.33%100%86.21%82.89%115, 129–131, 161, 222, 225, 235, 238, 248, 251, 419–421, 425–426, 453, 519, 603, 615, 653, 655, 699, 711, 714, 716, 729, 742–743, 747–748, 768
contracts/bridge/asset-router
   AssetRouterBase.sol97.14%100%100%96.55%67
   L1AssetRouter.sol88.17%100%89.29%87.97%106, 232, 270, 286, 373, 384, 415, 454–455, 469, 500, 572, 661, 672, 686, 691, 74, 90, 98
contracts/bridge/interfaces
   AssetHandlerModifiers.sol75%100%100%66.67%13
contracts/bridge/ntv
   L1NativeTokenVault.sol86.72%100%90.48%85.98%172–178, 180, 248–249, 251, 262, 264, 270, 94
   NativeTokenVaultBase.sol89.08%100%91.67%88.67%106, 238, 243, 260, 278, 283, 299, 318, 326, 495, 510, 538, 571–572, 576–577, 90
   UpgradeableBeaconDeployer.sol0%100%0%0%15–16, 18, 20–21
contracts/bridgehub
   BridgehubBase.sol80.48%100%83.78%79.77%137, 145, 150–152, 159, 177, 217–218, 227, 242, 281, 284, 303, 319, 350, 388–389, 484, 488, 492–493, 512, 515, 571, 575, 578, 613–614, 618–619, 627–628, 632–633
   CTMDeploymentTracker.sol73.47%100%81.82%71.05%107, 111, 115, 140, 144–145, 33, 41, 66, 79–80
   ChainAssetHandlerBase.sol72.88%100%75%72.55%131, 148, 151, 163–164, 209, 259–260, 264–265, 83, 90–91, 99
   L1Bridgehub.sol87.70%100%92.86%87.04%100–101, 110, 120, 135, 252, 325, 329–330, 333, 65–66, 86, 96
   L1ChainAssetHandler.sol77.78%100%71.43%80%35–36, 44–45
   L1MessageRoot.sol78.57%100%75%80%36–37
   L2Bridgehub.sol80.56%100%75%82.14%108, 65, 81–82, 93
   L2ChainAssetHandler.sol80.65%100%75%82.61%47–48, 70, 94
   L2MessageRoot.sol34.38%100%50%30.77%39–40, 43–44, 50, 68, 74–75, 79, 81, 83, 86–87, 89, 93–96
   L2MessageVerification.sol100%100%100%100%
   MessageRootBase.sol56.14%100%63.64%54.35%107–109, 115–117, 126, 132, 144, 154, 159–164, 166–170
contracts/common
   ReentrancyGuard.sol95%100%100%94.12%79
contracts/common/l2-helpers
   L2ContractHelper.sol84.91%100%100%82.22%102, 108, 112, 129, 134, 73, 79, 83
   SystemContractsCaller.sol0%100%0%0%102, 114, 122–125, 128, 135–139, 141–142, 32–34, 37, 44–45, 47, 49, 51, 53, 66, 69, 72, 75, 78, 83, 89, 91, 93, 96, 98
contracts/common/libraries
   DataEncoding.sol85.11%100%100%81.58%109–110, 117–118, 163, 177, 45
   DynamicIncrementalMerkle.sol73.91%100%80%73.17%66–70, 72–74, 76–78
   FullMerkle.sol100%100%100%100%
   Merkle.sol98.15%100%100%97.96%83
   MessageHashing.sol95.16%100%100%94.64%113, 77, 94
   SemVer.sol100%100%100%100%
   UncheckedMath.sol100%100%100%100%
   UnsafeBytes.sol100%100%100%100%
contracts/governance
   AccessControlRestriction.sol100%100%100%100%
   ChainAdmin.sol97.87%100%100%97.30%39
   ChainAdminOwnable.sol44.83%100%40%45.83%28, 38–40, 46–48, 57, 66, 77–79, 81
   Governance.sol100%100%100%100%
   L2ProxyAdminDeployer.sol0%100%0%0%16–18, 20
   PermanentRestriction.sol88.80%100%100%87.39%104, 111–112, 200–201, 204–205, 208, 210–211, 240, 288, 310, 341
   ServerNotifier.sol93.10%100%100%90.91%55, 65
   TransitionaryOwner.sol0%100%0%0%16–17, 21–23
contracts/governance/restriction
   Restriction.sol100%100%100%100%
   RestrictionValidator.sol100%100%100%100%
contracts/l2-upgrades
   L2ComplexUpgrader.sol0%100%0%0%23, 25–26, 40, 45, 47, 57, 63–64, 71, 80–82, 85, 87–88
   L2GenesisForceDeploymentsHelper.sol0%100%0%0%100, 107–108, 111–113, 119, 127, 131, 136, 138, 148, 157, 160, 165, 175, 177–178, 181, 184, 190, 194, 198, 209, 218, 223, 225, 233, 244, 258, 264, 284, 292–293, 296–297, 299, 306, 312, 33–36, 44, 47–48, 53, 59–61, 69–71, 73, 83, 91, 95
   L2GenesisUpgrade.sol0%100%0%0%24, 31–32, 37–38, 42, 50
contracts/state-transition
   AccessControlEnumerablePerChainAddressUpgradeable.sol98.15%100%100%97.67%179
   ChainTypeManager.sol85.93%100%84.62%86.25%111, 123, 129, 137–138, 245–248, 261–264, 279, 409, 471, 499, 506, 533, 581,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.