NFTBridge
60,000 USDC
View results
Submission Details
Severity: low
Invalid

The bridge Could Even Be Used to Cross-chain ERC20 in `Starknet` for ERC721 in `Ethereum`

Summary

In the bridge::deposit_tokens function, the ctype is automatically assumed to be CollectionType::ERC721 without any validation of the token’s interface. This implies that any token passed in could mistakenly be treated as an ERC721. Later in the escrow_deposit_tokens function, the erc721.transfer_from(from, to, token_id) method is invoked to ensure that NFTs are deposited. However, both ERC20 and ERC721 tokens have a transfer_from function. As a result, if a user passes in an ERC20 address, the deposit_tokens function would still succeed, leading to the creation of an ERC721 token on the Ethereum mainnet. This inconsistency could undermine the intended functionality.

Vulnerability Details

In bridge::deposit_tokens, the ctype is automatically set to CollectionType::ERC721 without any validation to ensure that the contract is indeed an ERC721 token.

@=> let ctype = CollectionType::ERC721;
let erc721_metadata = erc721_metadata(collection_l2, Option::Some(token_ids));
let (name, symbol, base_uri, uris) = match erc721_metadata {
Option::Some(data) => (data.name, data.symbol, data.base_uri, data.uris),
Option::None => ("", "", "", array![].span())
};
escrow_deposit_tokens(ref self, collection_l2, from, token_ids);

Subsequently, in the escrow_deposit_tokens function, the erc721.transfer_from(from, to, token_id) method is called to facilitate the NFT deposit. Typically, addresses that do not implement transfer_from would fail at this stage.

fn escrow_deposit_tokens(
ref self: ContractState,
contract_address: ContractAddress,
from: ContractAddress,
token_ids: Span<u256>,
) {
let to = starknet::get_contract_address();
let erc721 = IERC721Dispatcher { contract_address };
let mut i = 0_usize;
loop {
if i == token_ids.len() {
break ();
}
let token_id = *token_ids[i];
@=> erc721.transfer_from(from, to, token_id);
self.escrow.write((contract_address, token_id), from);
i += 1;
};
}

However, both ERC20 and ERC721 tokens implement the transfer_from(ContractAddress,ContractAddress,u256) function. This means an ERC20 token could still be deposited successfully, resulting in the creation of an ERC721 token on the Ethereum mainnet. This discrepancy compromises the intended behavior of the cross-chain bridge.

Impact

An ERC20 token could be erroneously used to bridge from Starknet to Ethereum as an ERC721 token, compromising the intended functionality and potentially leading to unintended consequences.

Tools Used

Manual

Recommendations

It is recommended to implement interface checks on the collection to ensure that the correct token type is being processed.

Updates

Lead Judging Commences

n0kto Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational / Gas

Please, do not suppose impacts, think about the real impact of the bug and check the CodeHawks documentation to confirm: https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity A PoC always helps to understand the real impact possible.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.