Zero length array is possible to be bridged from L2 to L1, making the length of the array _collections
on L1 long, so that users must pay extra gas when withdrawing on L1.
It is possible to call the function deposit_tokens
on L2 while token_ids
is an array with length zero.
As a result:
uris will be an array will length zero.
no token will be escrowed.
request hash will include an array with length zero
On L1 side, during withdrawal, no NFT will be withdrawn or minted since req.tokenIds.length
is zero. Only if the associated L1-collection is not present, it will be deployed.
A malicious user can apply the following grieving attack:
The malicious user calls the function deposit_tokens
with the following parameters:
collection_l2
: Any token address whether ERC20, ERC721, or ERC1155. There will be no issue because no token is going to be escrowed, only it is important that the token address has name()
and symbol()
, so that during getting erc721 metadata it does not panic.
https://github.com/Cyfrin/2024-07-ark-project/blob/main/apps/blockchain/starknet/src/token/collection_manager.cairo#L67-L74
token_ids
: An array with length zero.
The malicious user does it many times for different token addresses on Starknet.
On L1 side, when the gas price is low, the malicious user calls the function withdrawTokens
many times to conclude those zero token bridged messages. By doing so, no NFT will be minted or withdrawn, but each time a new ERC721Bridgeable
will be deployed. More importantly, the newly-deployed ERC721Bridgeable
will be added to the array of _collections
. So, it will become very long.
https://github.com/Cyfrin/2024-07-ark-project/blob/main/apps/blockchain/ethereum/src/Bridge.sol#L352
Later, when any honest user intends to bridge an NFT from L2 to L1, on L1, during withdrawal when the function _whiteListCollection
is called, it will go over all the elements in the array _collections
. This could be highly-gas consuming (in the worst low-probable case it will be over the block gas limit) for the users.
https://github.com/Cyfrin/2024-07-ark-project/blob/main/apps/blockchain/ethereum/src/Bridge.sol#L192
In summary, the malicious user bridges no NFT from L2 to L1 (without owning any NFT, so it makes the attack easy). Then, on L1, a new element will be added to the array _collections
making it long enough so that later honest users must pay extra gas when they intend to withdraw their NFTs on L1.
Please note that on L1, it is disallowed to bridge zero-length array to L2.
https://github.com/Cyfrin/2024-07-ark-project/blob/main/apps/blockchain/ethereum/src/Escrow.sol#L33
The following test shows depositing with zero length array on L2.
Gas grieving attack
Bridging zero length array from L2 to L1 should be disallowed.
Likelyhood: High, once the whitelist option is disabled, collections will grow. Impact: High, withdraw won’t be possible because of Out-Of-Gas.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.