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

fix: EVM-708 bridge fixes #703

Merged
merged 19 commits into from
Aug 16, 2024
Merged

Conversation

kelemeno
Copy link
Contributor

What ❔

  • l2SharedBridge address splicing in GatewayUpgrade
  • fixed NTV address in Standard token
  • check legacy token is deployed in bridgeMint

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.

@kelemeno kelemeno changed the title bridge fixes fix: EVM-708 bridge fixes Aug 15, 2024
Copy link

github-actions bot commented Aug 15, 2024

Changes to gas cost

Generated at commit: 96222eb0ec98fcb5b18b98e05d9683df3bd15a0b, compared to commit: df1c5c8576133acd9531cbd36987c201e7284926

🧾 Summary (100% most significant diffs)

Contract Method Avg (+/-) %
L1AssetRouter bridgeRecoverFailedTransfer
bridgehubConfirmL2Transaction
bridgehubDeposit
bridgehubDepositBaseToken
chainBalance
claimFailedDeposit
depositHappened
depositLegacyErc20Bridge
finalizeWithdrawal
finalizeWithdrawalLegacyErc20Bridge
nullifyChainBalanceByNTV
pause
setAssetHandlerAddressThisChain
setL1Erc20Bridge
setNativeTokenVault
transferTokenToNTV
unpause
+22 ❌
+22 ❌
+14 ❌
+22 ❌
+22 ❌
-88 ✅
+22 ❌
+22 ❌
+22 ❌
+22 ❌
+22 ❌
-87 ✅
-88 ✅
+22 ❌
+22 ❌
+22 ❌
-67 ✅
+0.05%
+0.11%
+0.02%
+0.04%
+2.27%
-0.16%
+2.46%
+0.02%
+0.04%
+0.02%
+0.47%
-0.34%
-0.18%
+0.09%
+0.09%
+0.23%
-0.77%
TransparentUpgradeableProxy bridgeRecoverFailedTransfer
bridgehubConfirmL2Transaction
bridgehubDeposit
bridgehubDepositBaseToken
claimFailedDeposit
depositHappened
depositLegacyErc20Bridge
finalizeWithdrawal
finalizeWithdrawalLegacyErc20Bridge
legacyBridge
nativeTokenVault
nullifyChainBalanceByNTV
pause
paused
registerToken
setL1Erc20Bridge
setNativeTokenVault
transferFundsFromSharedBridge
transferTokenToNTV
unpause
updateChainBalancesFromSharedBridge
+22 ❌
+22 ❌
+14 ❌
+21 ❌
-88 ✅
+19 ❌
+22 ❌
+22 ❌
+22 ❌
+20 ❌
-59 ✅
+22 ❌
-87 ✅
+22 ❌
-87 ✅
+22 ❌
+22 ❌
+17 ❌
+22 ❌
-67 ✅
+44 ❌
+0.03%
+0.05%
+0.02%
+0.03%
-0.11%
+0.78%
+0.02%
+0.02%
+0.02%
+0.99%
-2.85%
+0.07%
-0.16%
+2.25%
-0.08%
+0.04%
+0.04%
+0.03%
+0.07%
-0.21%
+0.09%
DummyBridgehubSetter addToken
initialize
removeStateTransitionManager
setHyperchain
setSTM
-21 ✅
-44 ✅
+2 ❌
+1 ❌
+24 ❌
-0.06%
-0.18%
+0.01%
+0.00%
+0.05%
L1NativeTokenVault transferFundsFromSharedBridge
updateChainBalancesFromSharedBridge
+18 ❌
+44 ❌
+0.08%
+0.17%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
L1AssetRouter 4,210,539 (+13,617) bridgeRecoverFailedTransfer
bridgehubConfirmL2Transaction
bridgehubDeposit
bridgehubDepositBaseToken
chainBalance
claimFailedDeposit
depositHappened
depositLegacyErc20Bridge
finalizeWithdrawal
finalizeWithdrawalLegacyErc20Bridge
legacyBridge
nativeTokenVault
nullifyChainBalanceByNTV
pause
paused
setAssetHandlerAddressThisChain
setL1Erc20Bridge
setNativeTokenVault
transferTokenToNTV
unpause
14,218 (+22)
4,936 (+22)
10,288 (+22)
646 (+22)
702 (+22)
9,474 (-88)
663 (+22)
10,315 (+22)
10,746 (+22)
91,066 (+22)
392 (+22)
370 (-67)
2,690 (+22)
25,743 (-87)
371 (+22)
7,650 (-88)
4,794 (+22)
4,785 (+22)
2,618 (+22)
8,620 (-67)
+0.15%
+0.45%
+0.21%
+3.53%
+3.24%
-0.92%
+3.43%
+0.21%
+0.21%
+0.02%
+5.95%
-15.33%
+0.82%
-0.34%
+6.30%
-1.14%
+0.46%
+0.46%
+0.85%
-0.77%
48,458 (+22)
19,565 (+22)
57,264 (+14)
56,121 (+22)
990 (+22)
53,917 (-88)
918 (+22)
112,210 (+22)
61,523 (+22)
99,880 (+22)
677 (+22)
655 (-67)
4,655 (+22)
25,743 (-87)
371 (+22)
49,187 (-88)
24,395 (+22)
24,373 (+22)
9,402 (+22)
8,620 (-67)
+0.05%
+0.11%
+0.02%
+0.04%
+2.27%
-0.16%
+2.46%
+0.02%
+0.04%
+0.02%
+3.36%
-9.28%
+0.47%
-0.34%
+6.30%
-0.18%
+0.09%
+0.09%
+0.23%
-0.77%
47,671 (+22)
26,880 (+22)
58,833 (+22)
46,926 (+22)
702 (+22)
64,114 (-88)
663 (+22)
163,132 (+22)
68,054 (+22)
99,880 (+22)
392 (+22)
370 (-67)
5,638 (+22)
25,743 (-87)
371 (+22)
49,450 (-88)
24,891 (+22)
24,869 (+22)
10,129 (+22)
8,620 (-67)
+0.05%
+0.08%
+0.04%
+0.05%
+3.24%
-0.14%
+3.43%
+0.01%
+0.03%
+0.02%
+5.95%
-15.33%
+0.39%
-0.34%
+6.30%
-0.18%
+0.09%
+0.09%
+0.22%
-0.77%
84,274 (+22)
26,880 (+22)
106,811 (-66)
122,082 (+22)
2,702 (+22)
84,266 (-88)
2,663 (+22)
163,185 (+22)
99,462 (+22)
108,695 (+22)
2,392 (+22)
2,370 (-67)
5,638 (+22)
25,743 (-87)
371 (+22)
49,450 (-88)
24,891 (+22)
24,869 (+22)
17,138 (+22)
8,620 (-67)
+0.03%
+0.08%
-0.06%
+0.02%
+0.82%
-0.10%
+0.83%
+0.01%
+0.02%
+0.02%
+0.93%
-2.75%
+0.39%
-0.34%
+6.30%
-0.18%
+0.09%
+0.09%
+0.13%
-0.77%
4 (0)
3 (0)
11 (0)
9 (0)
1,108 (0)
9 (0)
94 (0)
3 (0)
22 (0)
2 (0)
7 (0)
7 (0)
3 (0)
2 (0)
3 (0)
159 (0)
81 (0)
81 (0)
5 (0)
1 (0)
TransparentUpgradeableProxy 845,359 (0) bridgeRecoverFailedTransfer
bridgehubConfirmL2Transaction
bridgehubDeposit
bridgehubDepositBaseToken
chainBalance
claimFailedDeposit
depositHappened
depositLegacyErc20Bridge
finalizeWithdrawal
finalizeWithdrawalLegacyErc20Bridge
legacyBridge
nativeTokenVault
nullifyChainBalanceByNTV
pause
paused
registerToken
setL1Erc20Bridge
setNativeTokenVault
transferFundsFromSharedBridge
transferTokenToNTV
unpause
updateChainBalancesFromSharedBridge
45,769 (+22)
34,170 (+22)
39,847 (+22)
30,029 (+22)
631 (0)
39,972 (-88)
1,297 (+22)
39,992 (+22)
41,429 (+22)
114,008 (+22)
625 (0)
625 (0)
31,409 (+22)
53,932 (-87)
999 (+22)
29,012 (0)
33,130 (+22)
33,127 (+22)
37,521 (0)
31,194 (+22)
32,009 (-67)
48,878 (+44)
+0.05%
+0.06%
+0.06%
+0.07%
0.00%
-0.22%
+1.73%
+0.06%
+0.05%
+0.02%
0.00%
0.00%
+0.07%
-0.16%
+2.25%
0.00%
+0.07%
+0.07%
0.00%
+0.07%
-0.21%
+0.09%
76,905 (+22)
48,790 (+22)
84,397 (+14)
80,529 (+21)
1,609 (+9)
77,594 (-88)
2,466 (+19)
133,616 (+22)
88,706 (+22)
122,629 (+22)
2,033 (+20)
2,013 (-59)
31,409 (+22)
53,932 (-87)
999 (+22)
111,599 (-87)
52,949 (+22)
52,927 (+22)
49,236 (+17)
31,194 (+22)
32,009 (-67)
48,992 (+44)
+0.03%
+0.05%
+0.02%
+0.03%
+0.56%
-0.11%
+0.78%
+0.02%
+0.02%
+0.02%
+0.99%
-2.85%
+0.07%
-0.16%
+2.25%
-0.08%
+0.04%
+0.04%
+0.03%
+0.07%
-0.21%
+0.09%
74,680 (+22)
56,101 (+22)
88,629 (+22)
76,293 (+22)
1,358 (0)
82,427 (-88)
1,297 (+22)
180,396 (+22)
94,892 (+22)
122,629 (+22)
1,020 (+22)
998 (-67)
31,409 (+22)
53,932 (-87)
999 (+22)
110,694 (-88)
53,451 (+22)
53,429 (+22)
48,960 (+22)
31,194 (+22)
32,009 (-67)
48,992 (+44)
+0.03%
+0.04%
+0.02%
+0.03%
0.00%
-0.11%
+1.73%
+0.01%
+0.02%
+0.02%
+2.20%
-6.29%
+0.07%
-0.16%
+2.25%
-0.08%
+0.04%
+0.04%
+0.04%
+0.07%
-0.21%
+0.09%
112,494 (+22)
56,101 (+22)
127,154 (-66)
121,160 (+18)
9,858 (0)
102,351 (-88)
9,797 (+22)
180,461 (+22)
124,796 (+22)
131,251 (+22)
9,520 (+22)
9,498 (-67)
31,409 (+22)
53,932 (-87)
999 (+22)
113,550 (-88)
53,451 (+22)
53,429 (+22)
60,001 (+22)
31,194 (+22)
32,009 (-67)
49,106 (+44)
+0.02%
+0.04%
-0.05%
+0.01%
0.00%
-0.09%
+0.23%
+0.01%
+0.02%
+0.02%
+0.23%
-0.70%
+0.07%
-0.16%
+2.25%
-0.08%
+0.04%
+0.04%
+0.04%
+0.07%
-0.21%
+0.09%
4 (0)
3 (0)
11 (0)
9 (0)
2,641 (0)
9 (0)
106 (0)
3 (0)
22 (0)
2 (0)
8 (0)
8 (0)
1 (0)
2 (0)
3 (0)
159 (0)
81 (0)
81 (0)
5 (0)
1 (0)
1 (0)
2 (0)
DummyBridgehubSetter 3,943,444 (+43,680) addStateTransitionManager
addToken
initialize
proveL1ToL2TransactionStatus
proveL2LogInclusion
removeStateTransitionManager
setHyperchain
setPendingAdmin
setSTM
23,875 (0)
24,112 (-22)
24,188 (-44)
0 (0)
0 (0)
23,851 (0)
111,406 (0)
26,052 (0)
44,209 (+23)
0.00%
-0.09%
-0.18%
+∞%
+∞%
0.00%
0.00%
0.00%
+0.05%
41,137 (-1)
36,571 (-21)
24,188 (-44)
1,390 (-15)
1,508 (+2)
25,512 (+2)
111,444 (+1)
37,994 (-1)
44,247 (+24)
-0.00%
-0.06%
-0.18%
-1.07%
+0.13%
+0.01%
+0.00%
-0.00%
+0.05%
47,566 (0)
36,850 (-16)
24,188 (-44)
996 (-9)
1,111 (-3)
26,090 (+229)
111,466 (+12)
37,962 (0)
44,269 (+35)
0.00%
-0.04%
-0.18%
-0.90%
-0.27%
+0.89%
+0.01%
0.00%
+0.08%
47,566 (0)
47,587 (-22)
24,188 (-44)
3,661 (+7)
3,888 (-7)
26,318 (0)
111,466 (0)
49,872 (0)
44,269 (+23)
0.00%
-0.05%
-0.18%
+0.19%
-0.18%
0.00%
0.00%
0.00%
+0.05%
3,584 (0)
1,536 (0)
15 (0)
512 (0)
512 (0)
2,046 (-2)
768 (0)
512 (0)
768 (0)
L1NativeTokenVault 1,937,741 (0) registerToken
transferFundsFromSharedBridge
updateChainBalancesFromSharedBridge
484 (0)
8,945 (0)
25,203 (+44)
0.00%
0.00%
+0.17%
80,830 (-73)
21,718 (+18)
25,203 (+44)
-0.09%
+0.08%
+0.17%
82,362 (-88)
20,628 (+22)
25,203 (+44)
-0.11%
+0.11%
+0.17%
84,990 (-88)
33,568 (+22)
25,203 (+44)
-0.10%
+0.07%
+0.17%
191 (0)
5 (0)
2 (0)
MerkleTest 468,218 (0) calculateRoot(bytes32[],uint256,bytes32) 606 (0) 0.00% 2,920 (-2) -0.07% 2,943 (0) 0.00% 2,987 (0) 0.00% 261 (0)
MerkleTreeNoSort 534,636 (0) getProof 32,953 (0) 0.00% 33,182 (+3) +0.01% 33,193 (0) 0.00% 33,215 (0) 0.00% 273 (0)
MessageRoot 1,281,716 (+12)
TestnetERC20Token 640,439 (-24)
DummyBridgehub 172,411 (-24)
DummyStateTransitionManager 3,997,819 (+12)
ReenterL1ERC20Bridge 321,825 (+12)
DiamondInit 568,496 (+12)
DiamondProxy 1,939,890 (-516,812)
MailboxFacet 2,956,793 (+12)
TestBaseFacet 242,740 (-12)

function setLegacyBaseTokenAssetId(uint256 _chainId) external {
address token = baseToken[_chainId];
require(token != address(0), "BH: token not set");
baseTokenAssetId[_chainId] = DataEncoding.encodeNTVAssetId(block.chainid, token);
Copy link
Collaborator

@StanislavBreadless StanislavBreadless Aug 15, 2024

Choose a reason for hiding this comment

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

should be checked that the chain does not yet have the base token asset id set.

Probably reverting in case the token is set is too much (since the method is public and be frontrun), but at least not overwriting the base token should be done in case some chains have custom asset handler for base token

@@ -183,6 +183,19 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
require(token != address(0), "BH: token not set");
baseTokenAssetId[_chainId] = DataEncoding.encodeNTVAssetId(block.chainid, token);
}

/// @notice Used to set the legacy chain address for the upgrade.
/// @notice This has to be used after the BH but before the STM is upgraded.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the comment is not correct, it has to be used after STM is upgraded, since getHyperchainLegacy is available only on the new one

Copy link

Coverage after merging kl/l2-legacy-bridge-splicing into kl/sync-layer-reorg will be

88.68%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
../da-contracts/contracts
   RollupL1DAValidator.sol67.11%50%83.33%73.91%134, 137, 137, 137, 139, 170, 172, 25, 25, 25–26, 26, 26, 28, 30–31, 35–36, 59, 61, 61, 61–62, 64
contracts/bridge
   BridgeHelper.sol100%100%100%100%
   L1AssetRouter.sol95.19%89.29%94.87%97.88%137, 152, 209, 229, 274, 327, 379, 514, 531, 552, 735–736, 871
   L1ERC20Bridge.sol100%100%100%100%
   L1NativeTokenVault.sol96.12%97.62%84.62%97.30%252, 257, 45
contracts/bridgehub
   Bridgehub.sol72.94%44.30%83.33%86.43%103, 109, 114, 114, 153, 181, 181–182, 184–185, 185, 185–186, 192–193, 193, 193–194, 194, 194, 196–197, 197, 197–198, 289–292, 294–296, 298, 326, 380–381, 383, 383, 383, 426, 434–435, 438, 438, 438–439, 461, 499, 523–524, 603, 606–607, 611–612, 639–640, 645–646, 674, 679, 93, 98
   MessageRoot.sol91.38%61.54%100%100%156, 162, 69, 76, 94
   STMDeploymentTracker.sol79.49%50%90%94.12%110, 114, 31, 38, 61, 88, 91
contracts/common
   ReentrancyGuard.sol100%100%100%100%
contracts/common/libraries
   DataEncoding.sol80%100%100%66.67%72, 80
   DynamicIncrementalMerkle.sol74.42%100%80%72.22%67–70, 72–74, 76–78
   FullMerkle.sol100%100%100%100%
   L2ContractHelper.sol55.88%30%60%68.42%29, 32–33, 46–47, 47, 47, 49, 49, 49, 56, 86, 90
   Merkle.sol73.85%68.18%75%76.92%52–53, 53, 53–54, 54, 54–55, 55, 55, 57–59, 62, 65, 83
   MessageHashing.sol100%100%100%100%
   SemVer.sol100%100%100%100%
   UncheckedMath.sol100%100%100%100%
   UnsafeBytes.sol100%100%100%100%
contracts/governance
   ChainAdmin.sol22.22%20%33.33%20%16, 28–29, 38, 38, 38, 40, 42–43, 43, 46, 49
   Governance.sol99.07%96.77%100%100%44
contracts/state-transition
   StateTransitionManager.sol70.48%48.57%57.14%83.33%103, 130–132, 136, 189, 232, 239, 257, 263, 270, 282, 289, 296, 304, 311, 319, 326, 335, 335, 335–336, 349, 351, 417, 431, 434, 449, 454, 473, 73, 78, 84, 84
   TestnetVerifier.sol77.78%66.67%100%75%16, 32
   ValidatorTimelock.sol98.57%100%100%97.67%236
   Verifier.sol89.88%35.71%96.30%90.93%1673–1674, 287–302, 305–308, 311–318, 321–328, 331–332, 335–336, 339, 384–385, 395–396, 406–407, 417–418, 428–429, 444–445, 454, 454–455, 904–905
contracts/state-transition/chain-deps
   DiamondInit.sol88.24%70%100%100%33–37, 63
   DiamondProxy.sol80.77%62.50%100%88.24%16, 16, 16–17, 27
contracts/state-transition/chain-deps/facets
   Admin.sol82.14%56.82%85%92.31%103, 103, 103–105, 131, 131, 131–132, 132, 132, 134, 155, 201–202, 204, 218–219, 226, 245–246, 251, 288, 298, 302, 82, 91
   Executor.sol78.44%72.81%81.25%81.61%107, 167, 171–172, 172, 172–173, 173, 173, 184, 184, 188, 188, 188, 206, 220, 231, 234, 279, 279, 279, 282, 285, 287–288, 294–295, 314–317, 319, 36, 368, 368, 368–371, 373, 376, 379–380, 389, 405, 408–409, 411–413, 424–426, 446, 487, 494, 513, 518, 527–528, 579, 604–605
   Getters.sol83.19%66.67%84.09%84.85%104, 107, 113, 116, 127, 130, 172, 223, 229, 233, 64, 79, 84
   Mailbox.sol58.38%47.06%59.26%61.61%105, 121–122, 122, 122, 124–125, 133–135, 146, 157–158, 160–161, 163, 168, 172, 172–174, 174, 174–175, 178, 178, 178, 181, 183–184, 186, 191, 193, 196–197, 202–205, 208–209, 226, 232, 232, 232, 240, 245, 272, 301–302, 379, 390, 396, 535, 535, 535–536, 556, 65, 75, 97
   ZkSyncHyperchainBase.sol82.14%78.57%85.71%85.71%48, 56, 56, 56
contracts/state-transition/data-availability
   CalldataDA.sol100%100%100%100%
   CalldataDAGateway.sol85.71%66.67%100%100%27–28
   RelayedSLDAValidator.sol96.67%83.33%100%100%94
contracts/state-transition/libraries
   Diamond.sol94.81%86.49%100%97.73%110, 112, 114, 116, 119, 184, 294
   LibMap.sol100%100%100%100%
   PriorityQueue.sol100%100%100%100%
   PriorityTree.sol97.62%80%100%100%80
   

@kelemeno kelemeno merged commit 7d4b79c into kl/sync-layer-reorg Aug 16, 2024
23 checks passed
@kelemeno kelemeno deleted the kl/l2-legacy-bridge-splicing branch August 16, 2024 11:18
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.

2 participants