Skip to content

Commit

Permalink
(fix): merge conflicts + commit 7206350 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Raid Ateir committed Oct 30, 2024
1 parent 95f6991 commit 95d5c9f
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 62 deletions.
7 changes: 5 additions & 2 deletions l1-contracts/contracts/bridge/BridgedStandardERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ contract BridgedStandardERC20 is ERC20PermitUpgradeable, IBridgedStandardToken,

nativeTokenVault = msg.sender;

bytes memory nameBytes;
bytes memory symbolBytes;
bytes memory decimalsBytes;
// We parse the data exactly as they were created on the L1 bridge
(uint256, bytes memory nameBytes, bytes memory symbolBytes, bytes memory decimalsBytes) = DataEncoding
.decodeTokenData(_data);
// slither-disable-next-line unused-return
(, nameBytes, symbolBytes, decimalsBytes) = DataEncoding.decodeTokenData(_data);

ERC20Getters memory getters;
string memory decodedName;
Expand Down
2 changes: 2 additions & 0 deletions l1-contracts/contracts/bridge/L1ERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ contract L1ERC20Bridge is IL1ERC20Bridge, ReentrancyGuard {
_refundRecipient: _refundRecipient
});
// clearing approval
// slither-disable-next-line unused-return
IERC20(_l1Token).approve(address(L1_ASSET_ROUTER), 0);
depositAmount[msg.sender][_l1Token][l2TxHash] = _amount;
emit DepositInitiated({
Expand All @@ -224,6 +225,7 @@ contract L1ERC20Bridge is IL1ERC20Bridge, ReentrancyGuard {
function _approveFundsToAssetRouter(address _from, IERC20 _token, uint256 _amount) internal returns (uint256) {
uint256 balanceBefore = _token.balanceOf(address(this));
_token.safeTransferFrom(_from, address(this), _amount);
// slither-disable-next-line unused-return
_token.approve(address(L1_ASSET_ROUTER), _amount);
uint256 balanceAfter = _token.balanceOf(address(this));

Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/contracts/bridge/L1Nullifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ contract L1Nullifier is IL1Nullifier, ReentrancyGuard, Ownable2StepUpgradeable,
isWithdrawalFinalized[chainId][l2BatchNumber][l2MessageIndex] = true;

(bytes32 assetId, bytes memory transferData) = _verifyWithdrawal(_finalizeWithdrawalParams);

// Handling special case for withdrawal from ZKsync Era initiated before Shared Bridge.
if (_isPreSharedBridgeEraEthWithdrawal(chainId, l2BatchNumber)) {
// Checks that the withdrawal wasn't finalized already.
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/contracts/bridge/L2WrappedBaseToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ contract L2WrappedBaseToken is ERC20PermitUpgradeable, IL2WrappedBaseToken, IBri
/// Always reverts instead of minting anything!
/// Note: Use `deposit`/`depositTo` methods instead.
// solhint-disable-next-line no-unused-vars
function bridgeMint(address _to, uint256 _amount) external override onlyBridge {
function bridgeMint(address _to, uint256 _amount) external view override onlyBridge {
revert BridgeMintNotImplemented();
}

Expand Down
10 changes: 5 additions & 5 deletions l1-contracts/contracts/bridge/asset-router/L1AssetRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,15 @@ contract L1AssetRouter is AssetRouterBase, IL1AssetRouter, ReentrancyGuard {
// And if there is not enough allowance for the NTV
bool weCanTransfer = false;
if (l1Token.allowance(address(legacyBridge), address(this)) >= _amount) {
_originalCaller = address(legacyBridge);
_weCanTransfer = true;
_originalCaller = address(legacyBridge);
weCanTransfer = true;
} else if (
l1Token.allowance(_originalCaller, address(this)) >= _amount &&
l1Token.allowance(_originalCaller, address(nativeTokenVault)) < _amount
) {
_weCanTransfer = true;
}
if (_weCanTransfer) {
weCanTransfer = true;
}
if (weCanTransfer) {
// slither-disable-next-line arbitrary-send-erc20
l1Token.safeTransferFrom(_originalCaller, address(nativeTokenVault), _amount);
return true;
Expand Down
12 changes: 4 additions & 8 deletions l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
}

/// @dev Disable the initialization to prevent Parity hack.
/// @dev this contract is deployed in the L2GenesisUpgrade, and is meant as direct deployment without a proxy.
/// @dev this contract is deployed in the L2GenesisUpgrade, and is meant as direct deployment without a proxy.
/// @param _l1AssetRouter The address of the L1 Bridge contract.
constructor(
uint256 _l1ChainId,
uint256 _eraChainId,
address _l1AssetRouter,
address _legacySharedBridge,
bytes32 _baseTokenAssetId
bytes32 _baseTokenAssetId,
address _aliasedOwner
) AssetRouterBase(_l1ChainId, _eraChainId, IBridgehub(L2_BRIDGEHUB_ADDR)) {
L2_LEGACY_SHARED_BRIDGE = _legacySharedBridge;
if (_l1AssetRouter == address(0)) {
Expand All @@ -86,6 +87,7 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
assetHandlerAddress[_baseTokenAssetId] = L2_NATIVE_TOKEN_VAULT_ADDR;
BASE_TOKEN_ASSET_ID = _baseTokenAssetId;
_disableInitializers();
_transferOwnership(_aliasedOwner);
}

/// @inheritdoc IL2AssetRouter
Expand Down Expand Up @@ -144,12 +146,6 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
Internal & Helpers
//////////////////////////////////////////////////////////////*/

/// @inheritdoc AssetRouterBase
function _ensureTokenRegisteredWithNTV(address _token) internal override returns (bytes32 assetId) {
IL2NativeTokenVault nativeTokenVault = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR);
nativeTokenVault.ensureTokenIsRegistered(_token);
}

/// @notice Initiates a withdrawal by burning funds on the contract and sending the message to L1
/// where tokens would be unlocked
/// @param _assetId The asset id of the withdrawn asset
Expand Down
26 changes: 4 additions & 22 deletions l1-contracts/contracts/bridge/ntv/L2NativeTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract L2NativeTokenVault is IL2NativeTokenVault, NativeTokenVault {
bytes32 internal immutable L2_TOKEN_PROXY_BYTECODE_HASH;

/// @notice Initializes the bridge contract for later use.
/// @dev this contract is deployed in the L2GenesisUpgrade, and is meant as direct deployment without a proxy.
/// @dev this contract is deployed in the L2GenesisUpgrade, and is meant as direct deployment without a proxy.
/// @param _l1ChainId The L1 chain id differs between mainnet and testnets.
/// @param _l2TokenProxyBytecodeHash The bytecode hash of the proxy for tokens deployed by the bridge.
/// @param _aliasedOwner The address of the governor contract.
Expand Down Expand Up @@ -129,8 +129,7 @@ contract L2NativeTokenVault is IL2NativeTokenVault, NativeTokenVault {
}
}

<<<<<<< HEAD
/// @notice Ensures that the token is deployed inner for legacy tokens.
/// @notice Ensures that the token is deployed inner for legacy tokens.
function _ensureAndSaveTokenDeployedInnerLegacyToken(
bytes32 _assetId,
address _originToken,
Expand All @@ -148,11 +147,7 @@ contract L2NativeTokenVault is IL2NativeTokenVault, NativeTokenVault {
}

/// @notice Deploys the beacon proxy for the L2 token, while using ContractDeployer system contract or the legacy shared bridge.
/// @dev This function uses raw call to ContractDeployer to make sure that exactly `l2TokenProxyBytecodeHash` is used
=======
/// @notice Deploys the beacon proxy for the L2 token, while using ContractDeployer system contract.
/// @dev This function uses raw call to ContractDeployer to make sure that exactly `L2_TOKEN_PROXY_BYTECODE_HASH` is used
>>>>>>> origin/kl/n05-2gw
/// for the code of the proxy.
/// @param _salt The salt used for beacon proxy deployment of L2 bridged token.
/// @param _tokenOriginChainId The origin chain id of the token.
Expand Down Expand Up @@ -200,31 +195,18 @@ contract L2NativeTokenVault is IL2NativeTokenVault, NativeTokenVault {
//////////////////////////////////////////////////////////////*/

/// @notice Calculates L2 wrapped token address given the currently stored beacon proxy bytecode hash and beacon address.
<<<<<<< HEAD
/// @param _tokenOriginChainId The chain id of the origin token.
/// @param _l1Token The address of token on L1.
/// @param _nonNativeToken The address of token on its origin chain.
/// @return Address of an L2 token counterpart.
function calculateCreate2TokenAddress(
uint256 _tokenOriginChainId,
address _l1Token
) public view virtual override(INativeTokenVault, NativeTokenVault) returns (address) {
if (address(L2_LEGACY_SHARED_BRIDGE) != address(0) && _tokenOriginChainId == L1_CHAIN_ID) {
return L2_LEGACY_SHARED_BRIDGE.l2TokenAddress(_l1Token);
=======
/// @param _nonNativeToken The address of token on its origin chain..
/// @return Address of an L2 token counterpart.
function calculateCreate2TokenAddress(
uint256 _originChainId,
address _nonNativeToken
) public view virtual override(INativeTokenVault, NativeTokenVault) returns (address) {
bytes32 constructorInputHash = keccak256(abi.encode(address(bridgedTokenBeacon), ""));
bytes32 salt = _getCreate2Salt(_originChainId, _nonNativeToken);
if (address(L2_LEGACY_SHARED_BRIDGE) != address(0)) {
return L2_LEGACY_SHARED_BRIDGE.l2TokenAddress(_nonNativeToken);
>>>>>>> origin/kl/l01-2gw
} else {
bytes32 constructorInputHash = keccak256(abi.encode(address(bridgedTokenBeacon), ""));
bytes32 salt = _getCreate2Salt(_tokenOriginChainId, _l1Token);
bytes32 salt = _getCreate2Salt(_tokenOriginChainId, _nonNativeToken);
return
L2ContractHelper.computeCreate2Address(
address(this),
Expand Down
3 changes: 2 additions & 1 deletion l1-contracts/contracts/bridge/ntv/NativeTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,15 @@ abstract contract NativeTokenVault is INativeTokenVault, IAssetHandler, Ownable2

/// @notice Returns the origin chain id from the token data.
function tokenDataOriginChainId(bytes calldata _erc20Data) public view returns (uint256 tokenOriginChainId) {
// slither-disable-next-line unused-return
(tokenOriginChainId, , , ) = DataEncoding.decodeTokenData(_erc20Data);
if (tokenOriginChainId == 0) {
tokenOriginChainId = L1_CHAIN_ID;
}
}

/// @notice Checks that the assetId is correct for the origin token and chain.
function _assetIdCheck(uint256 _tokenOriginChainId, bytes32 _assetId, address _originToken) internal view {
function _assetIdCheck(uint256 _tokenOriginChainId, bytes32 _assetId, address _originToken) internal pure {
bytes32 expectedAssetId = DataEncoding.encodeNTVAssetId(_tokenOriginChainId, _originToken);
if (_assetId != expectedAssetId) {
// Make sure that a NativeTokenVault sent the message
Expand Down
8 changes: 1 addition & 7 deletions l1-contracts/contracts/bridgehub/Bridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,10 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
revert CTMNotRegistered();
}

<<<<<<< HEAD
bytes32 assetInfo = keccak256(abi.encode(L1_CHAIN_ID, sender, _additionalData));
ctmAssetIdToAddress[assetInfo] = _assetAddress;
ctmAssetIdFromAddress[_assetAddress] = assetInfo;
emit AssetRegistered(assetInfo, _assetAddress, _additionalData, msg.sender);
=======
bytes32 ctmAssetId = keccak256(abi.encode(L1_CHAIN_ID, sender, _additionalData));
ctmAssetIdToAddress[ctmAssetId] = _assetAddress;
ctmAssetIdFromAddress[_assetAddress] = ctmAssetId;
emit AssetRegistered(ctmAssetId, _assetAddress, _additionalData, msg.sender);
>>>>>>> origin/kl/l01-2gw
}

/*//////////////////////////////////////////////////////////////
Expand Down
3 changes: 0 additions & 3 deletions l1-contracts/contracts/common/libraries/DataEncoding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ library DataEncoding {

/// @notice Encodes the asset data by combining chain id, NTV as asset deployment tracker and asset data.
/// @param _chainId The id of the chain token is native to.
<<<<<<< HEAD
=======
/// @param _assetData The asset data that has to be encoded.
/// @return The encoded asset data.
function encodeNTVAssetId(uint256 _chainId, bytes32 _assetData) internal pure returns (bytes32) {
Expand All @@ -87,7 +85,6 @@ library DataEncoding {

/// @notice Encodes the asset data by combining chain id, NTV as asset deployment tracker and token address.
/// @param _chainId The id of the chain token is native to.
>>>>>>> origin/kl/l06-2gw
/// @param _tokenAddress The address of token that has to be encoded (asset data is the address itself).
/// @return The encoded asset data.
function encodeNTVAssetId(uint256 _chainId, address _tokenAddress) internal pure returns (bytes32) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ contract DummyChainTypeManagerForValidatorTimelock {
return zkChainAddress;
}

function getHyperchain(uint256) external view returns (address) {
return zkChainAddress;
}

function setZKChain(uint256, address _zkChain) external {
zkChainAddress = _zkChain;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract L2NativeTokenVaultDev is L2NativeTokenVault {

tokenBeacon.transferOwnership(owner());
bridgedTokenBeacon = IBeacon(address(tokenBeacon));
emit L2TokenBeaconUpdated(address(bridgedTokenBeacon), l2TokenProxyBytecodeHash);
emit L2TokenBeaconUpdated(address(bridgedTokenBeacon), L2_TOKEN_PROXY_BYTECODE_HASH);
}

function test() external pure {
Expand Down
2 changes: 2 additions & 0 deletions l1-contracts/contracts/state-transition/IChainTypeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ interface IChainTypeManager {

function getZKChain(uint256 _chainId) external view returns (address);

function getHyperchain(uint256 _chainId) external view returns (address);

function getZKChainLegacy(uint256 _chainId) external view returns (address);

function storedBatchZero() external view returns (bytes32);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ library PriorityTree {
}

/// @notice Reinitialize the tree from a commitment on L1.
function l1Reinit(Tree storage _tree, PriorityTreeCommitment memory _commitment) internal view {
function l1Reinit(Tree storage _tree, PriorityTreeCommitment memory _commitment) internal {
require(_tree.startIndex == _commitment.startIndex, "PT: invalid start index");
require(_tree.unprocessedIndex <= _commitment.unprocessedIndex, "PT: invalid unprocessed index");
require(_tree.tree._nextLeafIndex >= _commitment.nextLeafIndex, "PT: invalid next leaf index");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,8 @@ contract AssetRouterTest is L1ContractDeployer, ZKChainDeployer, TokenDeployer,
l2TokenAssetId = DataEncoding.encodeNTVAssetId(chainId, address(1));
bytes memory transferData = DataEncoding.encodeBridgeMintData({
_originalCaller: ETH_TOKEN_ADDRESS,
<<<<<<< HEAD
_l2Receiver: address(this),
_l1Token: _tokenAddress,
=======
_remoteReceiver: address(this),
_originToken: ETH_TOKEN_ADDRESS,
>>>>>>> origin/kl/l01-2gw
_amount: 100,
_erc20Metadata: BridgeHelper.getERC20Getters(_tokenAddress, chainId)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ contract L1AssetRouterFailTest is L1AssetRouterTest {
}

function test_nullifyChainBalanceByNTV_wrongCaller() public {
vm.expectRevert("L1N: not NTV");
vm.prank(owner);
vm.expectRevert(abi.encodeWithSelector(Unauthorized.selector, owner));
l1Nullifier.nullifyChainBalanceByNTV(chainId, address(token));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract L2Erc20BridgeTest is Test {
}

L2Utils.initSystemContracts();
L2Utils.forceDeployAssetRouter(L1_CHAIN_ID, ERA_CHAIN_ID, l1BridgeWallet, address(0));
L2Utils.forceDeployAssetRouter(L1_CHAIN_ID, ERA_CHAIN_ID, ownerWallet, l1BridgeWallet, address(0));
L2Utils.forceDeployNativeTokenVault({
_l1ChainId: L1_CHAIN_ID,
_aliasedOwner: ownerWallet,
Expand Down
6 changes: 4 additions & 2 deletions l1-contracts/test/foundry/l2/unit/utils/L2Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,20 @@ library L2Utils {
/// @notice Deploys the L2AssetRouter contract.
/// @param _l1ChainId The chain ID of the L1 chain.
/// @param _eraChainId The chain ID of the era chain.
/// @param _aliasedOwner The address of the owner of asset router.
/// @param _l1AssetRouter The address of the L1 asset router.
/// @param _legacySharedBridge The address of the legacy shared bridge.
function forceDeployAssetRouter(
uint256 _l1ChainId,
uint256 _eraChainId,
address _aliasedOwner,
address _l1AssetRouter,
address _legacySharedBridge
) internal {
// to ensure that the bytecode is known
bytes32 ethAssetId = DataEncoding.encodeNTVAssetId(_l1ChainId, ETH_TOKEN_ADDRESS);
{
new L2AssetRouter(_l1ChainId, _eraChainId, _l1AssetRouter, _legacySharedBridge, ethAssetId);
new L2AssetRouter(_l1ChainId, _eraChainId, _l1AssetRouter, _legacySharedBridge, ethAssetId, _aliasedOwner);
}

bytes memory bytecode = readEraBytecode("L2AssetRouter");
Expand All @@ -85,7 +87,7 @@ library L2Utils {
newAddress: L2_ASSET_ROUTER_ADDR,
callConstructor: true,
value: 0,
input: abi.encode(_l1ChainId, _eraChainId, _l1AssetRouter, _legacySharedBridge, ethAssetId)
input: abi.encode(_l1ChainId, _eraChainId, _l1AssetRouter, _legacySharedBridge, ethAssetId, _aliasedOwner)
});

vm.prank(L2_FORCE_DEPLOYER_ADDR);
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/foundry/l2/unit/weth/WETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Test} from "forge-std/Test.sol";
import {L2WrappedBaseToken} from "contracts/bridge/L2WrappedBaseToken.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts-v4/proxy/transparent/TransparentUpgradeableProxy.sol";

import {Unauthorized, UnimplementedMessage, BridgeMintNotImplemented} from "contracts/common/L1ContractErrors.sol";
import {Unauthorized, BridgeMintNotImplemented} from "contracts/common/L1ContractErrors.sol";

contract WethTest is Test {
L2WrappedBaseToken internal weth;
Expand Down

0 comments on commit 95d5c9f

Please sign in to comment.