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: kl/m01-2gw ctm AssetId #899

Open
wants to merge 2 commits into
base: gw-audit-2-fixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 9 additions & 7 deletions l1-contracts/contracts/bridgehub/Bridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";
import {DataEncoding} from "../common/libraries/DataEncoding.sol";
import {IZKChain} from "../state-transition/chain-interfaces/IZKChain.sol";

import {ETH_TOKEN_ADDRESS, TWO_BRIDGES_MAGIC_VALUE, BRIDGEHUB_MIN_SECOND_BRIDGE_ADDRESS, SETTLEMENT_LAYER_RELAY_SENDER} from "../common/Config.sol";
import {ETH_TOKEN_ADDRESS, TWO_BRIDGES_MAGIC_VALUE, BRIDGEHUB_MIN_SECOND_BRIDGE_ADDRESS, SETTLEMENT_LAYER_RELAY_SENDER, L1_SETTLEMENT_LAYER_VIRTUAL_ADDRESS} from "../common/Config.sol";
import {BridgehubL2TransactionRequest, L2Message, L2Log, TxStatus} from "../common/Messaging.sol";
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol";
import {IMessageRoot} from "./IMessageRoot.sol";
Expand Down Expand Up @@ -86,6 +86,9 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
/// @dev asset info used to identify chains in the Shared Bridge
mapping(bytes32 ctmAssetId => address ctmAddress) public ctmAssetIdToAddress;

/// @dev ctmAddress to ctmAssetId
mapping(address ctmAddress => bytes32 ctmAssetId) public ctmAssetIdFromAddress;

/// @dev used to indicate the currently active settlement layer for a given chainId
mapping(uint256 chainId => uint256 activeSettlementLayerChainId) public settlementLayer;

Expand Down Expand Up @@ -320,6 +323,7 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus

bytes32 assetInfo = keccak256(abi.encode(L1_CHAIN_ID, sender, _additionalData));
ctmAssetIdToAddress[assetInfo] = _assetAddress;
ctmAssetIdFromAddress[_assetAddress] = assetInfo;
StanislavBreadless marked this conversation as resolved.
Show resolved Hide resolved
emit AssetRegistered(assetInfo, _assetAddress, _additionalData, msg.sender);
}

Expand Down Expand Up @@ -422,11 +426,7 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
if (ctmAddress == address(0)) {
revert ChainIdNotRegistered(_chainId);
}
return ctmAssetId(chainTypeManager[_chainId]);
}

function ctmAssetId(address _ctmAddress) public view override returns (bytes32) {
return keccak256(abi.encode(L1_CHAIN_ID, address(l1CtmDeployer), bytes32(uint256(uint160(_ctmAddress)))));
return ctmAssetIdFromAddress[ctmAddress];
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -700,7 +700,9 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
bridgehubData.ctmData
);
bytes memory chainMintData = IZKChain(zkChain).forwardedBridgeBurn(
zkChainMap.get(_settlementChainId),
_settlementChainId == L1_CHAIN_ID
? L1_SETTLEMENT_LAYER_VIRTUAL_ADDRESS
: zkChainMap.get(_settlementChainId),
_originalCaller,
bridgehubData.chainData
);
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/contracts/bridgehub/IBridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ interface IBridgehub is IAssetHandler, IL1AssetHandler {

function ctmAssetIdFromChainId(uint256 _chainId) external view returns (bytes32);

function ctmAssetId(address _ctmAddress) external view returns (bytes32);
function ctmAssetIdFromAddress(address _ctmAddress) external view returns (bytes32);

function l1CtmDeployer() external view returns (ICTMDeploymentTracker);

Expand Down
5 changes: 5 additions & 0 deletions l1-contracts/contracts/common/Config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ address constant SETTLEMENT_LAYER_RELAY_SENDER = address(uint160(0x1111111111111
/// @dev The metadata version that is supported by the ZK Chains to prove that an L2->L1 log was included in a batch.
uint256 constant SUPPORTED_PROOF_METADATA_VERSION = 1;

/// @dev The virtual address of the L1 settlement layer.
address constant L1_SETTLEMENT_LAYER_VIRTUAL_ADDRESS = address(
uint160(uint256(keccak256("L1_SETTLEMENT_LAYER_VIRTUAL_ADDRESS")) - 1)
);

struct PriorityTreeCommitment {
uint256 nextLeafIndex;
uint256 startIndex;
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/deploy-scripts/DeployL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ contract DeployL1Script is Script {
vm.stopBroadcast();
console.log("CTM registered in CTMDeploymentTracker");

bytes32 assetId = bridgehub.ctmAssetId(addresses.stateTransition.stateTransitionProxy);
bytes32 assetId = bridgehub.ctmAssetIdFromAddress(addresses.stateTransition.stateTransitionProxy);
// console.log(address(bridgehub.ctmDeployer()), addresses.bridgehub.ctmDeploymentTrackerProxy);
// console.log(address(bridgehub.ctmDeployer().BRIDGE_HUB()), addresses.bridgehub.bridgehubProxy);
console.log(
Expand Down
Loading