Skip to content

Commit

Permalink
Fix audittens H07 (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless authored Dec 2, 2024
1 parent f7364fb commit a9a28a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 15 additions & 2 deletions l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {AddressAliasHelper} from "../../vendor/AddressAliasHelper.sol";
import {L2_NATIVE_TOKEN_VAULT_ADDR, L2_BRIDGEHUB_ADDR} from "../../common/L2ContractAddresses.sol";
import {L2ContractHelper} from "../../common/libraries/L2ContractHelper.sol";
import {DataEncoding} from "../../common/libraries/DataEncoding.sol";
import {EmptyAddress, InvalidCaller, AmountMustBeGreaterThanZero, AssetIdNotSupported} from "../../common/L1ContractErrors.sol";
import {TokenNotLegacy, EmptyAddress, InvalidCaller, AmountMustBeGreaterThanZero, AssetIdNotSupported} from "../../common/L1ContractErrors.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
Expand Down Expand Up @@ -304,7 +304,11 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
}

function _withdrawLegacy(address _l1Receiver, address _l2Token, uint256 _amount, address _sender) internal {
bytes32 assetId = DataEncoding.encodeNTVAssetId(L1_CHAIN_ID, l1TokenAddress(_l2Token));
address l1Address = l1TokenAddress(_l2Token);
if (l1Address == address(0)) {
revert TokenNotLegacy();
}
bytes32 assetId = DataEncoding.encodeNTVAssetId(L1_CHAIN_ID, l1Address);
bytes memory data = abi.encode(_amount, _l1Receiver);
_withdrawSender(assetId, data, _sender, false);
}
Expand All @@ -313,6 +317,15 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
/// @param _l2Token The address of token on L2.
/// @return The address of token on L1.
function l1TokenAddress(address _l2Token) public view returns (address) {
bytes32 assetId = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).assetId(_l2Token);
if (assetId == bytes32(0)) {
return address(0);
}
uint256 originChainId = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).originChainId(assetId);
if (originChainId != L1_CHAIN_ID) {
return address(0);
}

return IBridgedStandardToken(_l2Token).l1Address();
}

Expand Down
2 changes: 2 additions & 0 deletions l1-contracts/contracts/common/L1ContractErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ error NotBridgehub(address addr);
error InvalidAddress(address expected, address actual);
// 0xfa5cd00f
error NotAllowed(address addr);
// 0x1850b46b
error TokenNotLegacy();
// 0x1929b7de
error IncorrectTokenAddressFromNTV(bytes32 assetId, address tokenAddress);
// 0x48c5fa28
Expand Down

0 comments on commit a9a28a2

Please sign in to comment.