Skip to content

Commit

Permalink
Fix H03 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless authored Nov 28, 2024
1 parent 7673edf commit a11df6a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
27 changes: 14 additions & 13 deletions l1-contracts/contracts/bridgehub/Bridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -226,32 +226,33 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
messageRoot = _messageRoot;
}

/// @notice Used for the upgrade to set the baseTokenAssetId previously stored as baseToken.
/// @param _chainId the chainId of the chain.
function setLegacyBaseTokenAssetId(uint256 _chainId) external override {
if (baseTokenAssetId[_chainId] != bytes32(0)) {
return;
}
address token = __DEPRECATED_baseToken[_chainId];
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 Used to set the legacy chain data for the upgrade.
/// @param _chainId The chainId of the legacy chain we are migrating.
function setLegacyChainAddress(uint256 _chainId) external override {
function registerLegacyChain(uint256 _chainId) external override {
address ctm = chainTypeManager[_chainId];
if (ctm == address(0)) {
revert ChainNotLegacy();
}
if (zkChainMap.contains(_chainId)) {
revert ChainAlreadyLive();
}

// From now on, since `zkChainMap` did not contain the chain, we assume
// that the chain is a legacy chain in the process of migration, i.e.
// its stored `baseTokenAssetId`, etc.

address token = __DEPRECATED_baseToken[_chainId];
require(token != address(0), "BH: token not set");

baseTokenAssetId[_chainId] = DataEncoding.encodeNTVAssetId(block.chainid, token);

address chainAddress = IChainTypeManager(ctm).getZKChainLegacy(_chainId);
if (chainAddress == address(0)) {
revert ChainNotLegacy();
}
_registerNewZKChain(_chainId, chainAddress);
messageRoot.addNewChain(_chainId);
settlementLayer[_chainId] = block.chainid;
}

//// Registry
Expand Down
6 changes: 2 additions & 4 deletions l1-contracts/contracts/bridgehub/IBridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,11 @@ interface IBridgehub is IAssetHandler, IL1AssetHandler {

function L1_CHAIN_ID() external view returns (uint256);

function setLegacyBaseTokenAssetId(uint256 _chainId) external;

function registerAlreadyDeployedZKChain(uint256 _chainId, address _hyperchain) external;

function setLegacyChainAddress(uint256 _chainId) external;

/// @notice return the ZK chain contract for a chainId
/// @dev It is a legacy method. Do not use!
function getHyperchain(uint256 _chainId) external view returns (address);

function registerLegacyChain(uint256 _chainId) external;
}
9 changes: 7 additions & 2 deletions l1-contracts/test/foundry/l1/integration/DeploymentTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {IZKChain} from "contracts/state-transition/chain-interfaces/IZKChain.sol
import {IChainTypeManager} from "contracts/state-transition/IChainTypeManager.sol";
import {DataEncoding} from "contracts/common/libraries/DataEncoding.sol";
import {IncorrectBridgeHubAddress} from "contracts/common/L1ContractErrors.sol";
import {MessageRoot} from "contracts/bridgehub/MessageRoot.sol";

contract DeploymentTests is L1ContractDeployer, ZKChainDeployer, TokenDeployer, L2TxMocker {
uint256 constant TEST_USERS_COUNT = 10;
Expand Down Expand Up @@ -106,8 +107,12 @@ contract DeploymentTests is L1ContractDeployer, ZKChainDeployer, TokenDeployer,
keccak256(abi.encode(randomChainId, 204)),
bytes32(uint256(uint160(address(chainTypeManager))))
);
bridgehub.setLegacyBaseTokenAssetId(randomChainId);
bridgehub.setLegacyChainAddress(randomChainId);
bridgehub.registerLegacyChain(randomChainId);

assertEq(bridgehub.settlementLayer(randomChainId), block.chainid);

address messageRoot = address(bridgehub.messageRoot());
assertTrue(MessageRoot(messageRoot).chainIndex(randomChainId) != 0);
}

function test_registerAlreadyDeployedZKChain() public {
Expand Down

0 comments on commit a11df6a

Please sign in to comment.