Several functions in the Ark protocol do not adhere to the Checks-Effects-Interactions (CEI) programming pattern, making them vulnerable to reentrancy attacks. This could allow an attacker to manipulate the contract state in unintended ways, potentially disrupting the normal functioning of the bridge or causing inconsistencies between L1 and L2.
The following functions do not respect the CEI pattern:
In Bridge.sol:
The depositTokens function performs external interactions before checking internal state:
In Escrow.sol:
The _depositIntoEscrow function performs token transfers before updating the escrow state:
The _withdrawFromEscrow function performs token transfers before updating the escrow state:
In Messaging.sol:
The _consumeMessageStarknet function interacts with the Starknet Core contract before checking internal state:
The potential impact of this vulnerability is significant. While the bridge only handles NFTs, an attacker could still exploit this flaw to manipulate the bridge state in unintended ways, disrupting the normal functioning of the protocol:
An attacker could create a malicious NFT contract that, when transferred, calls back into the depositTokens function. This could allow the attacker to deposit the same NFT multiple times before the escrow state is updated, potentially creating multiple bridge requests for a single NFT. This could lead to inconsistencies between L1 and L2, where the L2 side might mint multiple copies of the same NFT.
An attacker could execute L2 messages multiple times, leading to state inconsistencies between L1 and L2:
If an attacker can control an NFT contract on L1, they could create a withdrawTokens function that, when called, triggers a reentrancy attack on the _consumeMessageStarknet function. This could allow the attacker to consume the same L2 message multiple times before the _autoWithdrawn state is updated. As a result, the attacker might be able to mint multiple NFTs on L1 for a single withdrawal request from L2, effectively duplicating NFTs during the bridging process.
These scenarios could lead to severe disruptions in the bridge's operation, potentially allowing unauthorized minting or duplication of NFTs, and causing a loss of trust in the protocol.
Manual review - Foundry IDE
To resolve this vulnerability, it is recommended to restructure the mentioned functions to follow the CEI pattern:
Perform all necessary checks first.
Update the internal state of the contract.
Perform external interactions last.
For example, the depositTokens function in Bridge.sol could be restructured as follows:
For example, the _depositIntoEscrow function in Escrow.sol could be restructured as follows:
For example, the _withdrawFromEscrow function in Escrow.sol could be restructured as follows:
For example, the `_consumeMessageStarknet` function in Messaging.sol could be restructured as follows:
Impact: - NFT already bridged won’t be bridgeable anymore without being stuck. Likelyhood: Low. - Attackers will corrupt their own tokens, deploying a risky contract interacting with an upgradable proxy. They have to buy and sell them without real benefits, except being mean. Some really specific and rare scenario can also trigger that bug.
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.