Skip to content

Commit 255fbf7

Browse files
zkzoomer0xValera
andauthored
Stage v29 patch scripts (#1605)
Co-authored-by: 0xValera <[email protected]>
1 parent 97cc706 commit 255fbf7

File tree

19 files changed

+850
-111
lines changed

19 files changed

+850
-111
lines changed

AllContractsHashes.json

Lines changed: 90 additions & 90 deletions
Large diffs are not rendered by default.

l1-contracts/contracts/bridgehub/ChainAssetHandler.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {IZKChain} from "../state-transition/chain-interfaces/IZKChain.sol";
1414

1515
import {L1_SETTLEMENT_LAYER_VIRTUAL_ADDRESS} from "../common/Config.sol";
1616
import {IMessageRoot} from "./IMessageRoot.sol";
17-
import {HyperchainNotRegistered, IncorrectChainAssetId, IncorrectSender, NotAssetRouter, NotL1} from "./L1BridgehubErrors.sol";
17+
import {HyperchainNotRegistered, IncorrectChainAssetId, IncorrectSender, NotAssetRouter, NotL1, SLHasDifferentCTM} from "./L1BridgehubErrors.sol";
1818
import {ChainIdNotRegistered, MigrationPaused} from "../common/L1ContractErrors.sol";
1919

2020
import {AssetHandlerModifiers} from "../bridge/interfaces/AssetHandlerModifiers.sol";
@@ -146,6 +146,11 @@ contract ChainAssetHandler is
146146
bridgehubBurnData.chainId,
147147
bridgehubBurnData.ctmData
148148
);
149+
150+
// For security reasons, chain migration is temporarily restricted to settlement layers with the same CTM
151+
if (_settlementChainId != L1_CHAIN_ID && BRIDGEHUB.chainTypeManager(_settlementChainId) != ctm) {
152+
revert SLHasDifferentCTM();
153+
}
149154
}
150155
bytes memory chainMintData = IZKChain(zkChain).forwardedBridgeBurn(
151156
_settlementChainId == L1_CHAIN_ID

l1-contracts/contracts/bridgehub/L1BridgehubErrors.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ error NotCurrentSL(uint256 settlementLayerChainId, uint256 blockChainId);
3232
error NotInGatewayMode();
3333
// 0xecb34449
3434
error NotL1(uint256 l1ChainId, uint256 blockChainId);
35+
// 0x8eb4fc01
36+
error NotL2();
3537
// 0x23295f0e
3638
error NotOwner(address sender, address owner);
3739
// 0x693cd3dc
@@ -44,11 +46,11 @@ error OnlyBridgehub(address msgSender, address bridgehub);
4446
error OnlyBridgehubOrChainAssetHandler(address sender, address bridgehub, address chainAssetHandler);
4547
// 0x73fe6c1b
4648
error OnlyChain(address msgSender, address zkChainAddress);
47-
// 0xa7a05e40
48-
error OnlyL2();
4949
// 0xb78dbaa7
5050
error SecondBridgeAddressTooLow(address secondBridgeAddress, address minSecondBridgeAddress);
5151
// 0x90c7cbf1
5252
error SLNotWhitelisted();
53+
// 0x36917565
54+
error SLHasDifferentCTM();
5355
// 0x92626457
5456
error WrongCounterPart(address addressOnCounterPart, address l2BridgehubAddress);

l1-contracts/contracts/bridgehub/MessageRoot.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {Initializable} from "@openzeppelin/contracts-v4/proxy/utils/Initializabl
77
import {DynamicIncrementalMerkle} from "../common/libraries/DynamicIncrementalMerkle.sol";
88
import {IBridgehub} from "./IBridgehub.sol";
99
import {IMessageRoot} from "./IMessageRoot.sol";
10-
import {ChainExists, MessageRootNotRegistered, OnlyBridgehubOrChainAssetHandler, OnlyChain, OnlyL2} from "./L1BridgehubErrors.sol";
10+
import {ChainExists, MessageRootNotRegistered, OnlyBridgehubOrChainAssetHandler, OnlyChain, NotL2} from "./L1BridgehubErrors.sol";
1111
import {FullMerkle} from "../common/libraries/FullMerkle.sol";
1212

1313
import {MessageHashing} from "../common/libraries/MessageHashing.sol";
@@ -105,9 +105,9 @@ contract MessageRoot is IMessageRoot, Initializable {
105105
}
106106

107107
/// @notice Checks that the Chain ID is not L1 when adding chain batch root.
108-
modifier onlyL2Chain() {
108+
modifier onlyL2() {
109109
if (block.chainid == L1_CHAIN_ID) {
110-
revert OnlyL2();
110+
revert NotL2();
111111
}
112112
_;
113113
}
@@ -150,7 +150,7 @@ contract MessageRoot is IMessageRoot, Initializable {
150150
uint256 _chainId,
151151
uint256 _batchNumber,
152152
bytes32 _chainBatchRoot
153-
) external onlyChain(_chainId) onlyL2Chain {
153+
) external onlyChain(_chainId) onlyL2 {
154154
// Make sure that chain is registered.
155155
if (!chainRegistered(_chainId)) {
156156
revert MessageRootNotRegistered();

l1-contracts/contracts/state-transition/L1StateTransitionErrors.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ error MismatchNumberOfLayer1Txs(uint256 numberOfLayer1Txs, uint256 expectedLengt
6060
error NotAllBatchesExecuted();
6161
// 0xf05c64c6
6262
error NotChainAdmin(address prevMsgSender, address admin);
63+
// 0x8fd63d21
64+
error NotEraChain();
6365
// 0xa7050bf6
6466
error NotHistoricalRoot(bytes32);
6567
// 0x32ddf9a2

l1-contracts/contracts/state-transition/chain-deps/facets/Admin.sol

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ import {MAX_GAS_PER_TRANSACTION, ZKChainCommitment} from "../../../common/Config
99
import {FeeParams, PubdataPricingMode} from "../ZKChainStorage.sol";
1010
import {PriorityTree} from "../../../state-transition/libraries/PriorityTree.sol";
1111
import {PriorityQueue} from "../../../state-transition/libraries/PriorityQueue.sol";
12+
import {IZKChain} from "../../../state-transition/chain-interfaces/IZKChain.sol";
13+
import {IBridgehub} from "../../../bridgehub/IBridgehub.sol";
1214
import {ZKChainBase} from "./ZKChainBase.sol";
1315
import {IChainTypeManager} from "../../IChainTypeManager.sol";
1416
import {IL1GenesisUpgrade} from "../../../upgrades/IL1GenesisUpgrade.sol";
15-
import {AlreadyPermanentRollup, DenominatorIsZero, DiamondAlreadyFrozen, DiamondNotFrozen, HashMismatch, InvalidDAForPermanentRollup, InvalidPubdataPricingMode, PriorityTxPubdataExceedsMaxPubDataPerBatch, ProtocolIdMismatch, ProtocolIdNotGreater, TooMuchGas, Unauthorized} from "../../../common/L1ContractErrors.sol";
16-
import {AlreadyMigrated, ContractNotDeployed, ExecutedIsNotConsistentWithVerified, InvalidNumberOfBatchHashes, L1DAValidatorAddressIsZero, L2DAValidatorAddressIsZero, NotAllBatchesExecuted, NotChainAdmin, NotHistoricalRoot, NotL1, NotMigrated, OutdatedProtocolVersion, ProtocolVersionNotUpToDate, VerifiedIsNotConsistentWithCommitted} from "../../L1StateTransitionErrors.sol";
17+
import {AlreadyPermanentRollup, DenominatorIsZero, DiamondAlreadyFrozen, DiamondNotFrozen, HashMismatch, InvalidDAForPermanentRollup, InvalidPubdataPricingMode, NotAZKChain, PriorityTxPubdataExceedsMaxPubDataPerBatch, ProtocolIdMismatch, ProtocolIdNotGreater, TooMuchGas, Unauthorized} from "../../../common/L1ContractErrors.sol";
18+
import {AlreadyMigrated, ContractNotDeployed, ExecutedIsNotConsistentWithVerified, InvalidNumberOfBatchHashes, L1DAValidatorAddressIsZero, L2DAValidatorAddressIsZero, NotAllBatchesExecuted, NotChainAdmin, NotEraChain, NotHistoricalRoot, NotL1, NotMigrated, OutdatedProtocolVersion, ProtocolVersionNotUpToDate, VerifiedIsNotConsistentWithCommitted} from "../../L1StateTransitionErrors.sol";
1719
import {RollupDAManager} from "../../data-availability/RollupDAManager.sol";
1820
import {L2_DEPLOYER_SYSTEM_CONTRACT_ADDR} from "../../../common/l2-helpers/L2ContractAddresses.sol";
1921
import {AllowedBytecodeTypes, IL2ContractDeployer} from "../../../common/interfaces/IL2ContractDeployer.sol";
22+
import {L1_SETTLEMENT_LAYER_VIRTUAL_ADDRESS} from "../../../common/Config.sol";
2023

2124
// While formally the following import is not used, it is needed to inherit documentation from it
2225
import {IZKChainBase} from "../../chain-interfaces/IZKChainBase.sol";
@@ -299,6 +302,20 @@ contract AdminFacet is ZKChainBase, IAdmin {
299302
if (_originalCaller != s.admin) {
300303
revert NotChainAdmin(_originalCaller, s.admin);
301304
}
305+
306+
// We want to trust interop messages coming from Era chains which implies they can use only trusted settlement layers,
307+
// ie, controlled by the governance, which is currently Era Gateways and Ethereum.
308+
// Otherwise a malicious settlement layer could forge an interop message from an Era chain.
309+
if (_settlementLayer != L1_SETTLEMENT_LAYER_VIRTUAL_ADDRESS) {
310+
uint256 chainId = IZKChain(_settlementLayer).getChainId();
311+
if (_settlementLayer != IBridgehub(s.bridgehub).getZKChain(chainId)) {
312+
revert NotAZKChain(_settlementLayer);
313+
}
314+
if (s.chainTypeManager != IBridgehub(s.bridgehub).chainTypeManager(chainId)) {
315+
revert NotEraChain();
316+
}
317+
}
318+
302319
// As of now all we need in this function is the chainId so we encode it and pass it down in the _chainData field
303320
uint256 protocolVersion = abi.decode(_data, (uint256));
304321

l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {Math} from "@openzeppelin/contracts-v4/utils/math/Math.sol";
66

77
import {IMailbox} from "../../chain-interfaces/IMailbox.sol";
88
import {IMailboxImpl} from "../../chain-interfaces/IMailboxImpl.sol";
9-
import {IChainTypeManager} from "../../IChainTypeManager.sol";
109
import {IBridgehub} from "../../../bridgehub/IBridgehub.sol";
1110

1211
import {ITransactionFilterer} from "../../chain-interfaces/ITransactionFilterer.sol";
@@ -317,7 +316,7 @@ contract MailboxFacet is ZKChainBase, IMailboxImpl, MessageVerification {
317316
if (!IBridgehub(s.bridgehub).whitelistedSettlementLayers(s.chainId)) {
318317
revert NotSettlementLayer();
319318
}
320-
if (IChainTypeManager(s.chainTypeManager).getZKChain(_chainId) != msg.sender) {
319+
if (IBridgehub(s.bridgehub).getZKChain(_chainId) != msg.sender) {
321320
revert NotHyperchain();
322321
}
323322

l1-contracts/deploy-scripts/upgrade/DefaultEcosystemUpgrade.s.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ contract DefaultEcosystemUpgrade is Script, DeployL1Script {
121121
address ecosystemAdminAddress;
122122
uint256 governanceUpgradeTimerInitialDelay;
123123
uint256 oldProtocolVersion;
124-
uint256 v28ProtocolVersion;
125124
address oldValidatorTimelock;
126125
uint256 priorityTxsL2GasLimit;
127126
uint256 maxExpectedL1GasPrice;
@@ -530,7 +529,6 @@ contract DefaultEcosystemUpgrade is Script, DeployL1Script {
530529
newConfig.governanceUpgradeTimerInitialDelay = toml.readUint("$.governance_upgrade_timer_initial_delay");
531530

532531
newConfig.oldProtocolVersion = toml.readUint("$.old_protocol_version");
533-
newConfig.v28ProtocolVersion = toml.readUint("$.v28_protocol_version");
534532

535533
newConfig.priorityTxsL2GasLimit = toml.readUint("$.priority_txs_l2_gas_limit");
536534
newConfig.maxExpectedL1GasPrice = toml.readUint("$.max_expected_l1_gas_price");

l1-contracts/deploy-scripts/upgrade/EcosystemUpgrade_v29.s.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ contract EcosystemUpgrade_v29 is Script, DefaultEcosystemUpgrade {
101101
address[] internal oldValidatorTimelocks;
102102
address[] internal oldGatewayValidatorTimelocks;
103103
address protocolUpgradeHandlerImplementationAddress;
104+
uint256 v28ProtocolVersion;
104105

105106
/// @notice E2e upgrade generation
106107
function run() public virtual override {
@@ -116,6 +117,8 @@ contract EcosystemUpgrade_v29 is Script, DefaultEcosystemUpgrade {
116117
super.initializeConfig(newConfigPath);
117118
string memory toml = vm.readFile(newConfigPath);
118119

120+
v28ProtocolVersion = toml.readUint("$.v28_protocol_version");
121+
119122
bytes memory encodedOldValidatorTimelocks = toml.readBytes("$.V29.encoded_old_validator_timelocks");
120123
oldValidatorTimelocks = abi.decode(encodedOldValidatorTimelocks, (address[]));
121124

@@ -308,7 +311,7 @@ contract EcosystemUpgrade_v29 is Script, DefaultEcosystemUpgrade {
308311
uint256 l2GasLimit,
309312
uint256 l1GasPrice
310313
) public virtual returns (Call[] memory calls) {
311-
uint256 oldProtocolVersion = newConfig.v28ProtocolVersion;
314+
uint256 oldProtocolVersion = v28ProtocolVersion;
312315
Diamond.DiamondCutData memory upgradeCut = abi.decode(gatewayConfig.upgradeCutData, (Diamond.DiamondCutData));
313316

314317
bytes memory l2Calldata = abi.encodeCall(
@@ -351,7 +354,7 @@ contract EcosystemUpgrade_v29 is Script, DefaultEcosystemUpgrade {
351354
function prepareSetUpgradeDiamondCutOnL1Call() public virtual returns (Call[] memory calls) {
352355
calls = new Call[](1);
353356

354-
uint256 oldProtocolVersion = newConfig.v28ProtocolVersion;
357+
uint256 oldProtocolVersion = v28ProtocolVersion;
355358
Diamond.DiamondCutData memory upgradeCut = abi.decode(
356359
newlyGeneratedData.upgradeCutData,
357360
(Diamond.DiamondCutData)

0 commit comments

Comments
 (0)