Skip to main content

Avoiding common attacks

Here are some other common attacks that blockchain developers must be aware of:

  • Replay attacks: A replay attack allows an attacker to reuse a signed valid transaction multiple times. Tezos prevents most instances of this type of attack by requiring a transaction to be signed by a nonce, which changes each time the transaction is executed. Still, be aware that transactions on Tezos are publicly visible and the data in them can be seem by anyone.

  • Re-entrancy attacks: Re-entrancy attacks take advantage of the asynchronous nature of blockchain transactions. Attackers call a contract repeatedly and quickly to take advantage of flaws in a contract or make a denial of service attack.

    One of the most well-known examples of a re-entrancy attack occurred in 2016 when an attacker exploited a vulnerability in the DAO (Decentralized Autonomous Organization) contract on the Ethereum blockchain.

    These types of attacks are more difficult on Tezos because of how it puts operations in a specific order, as described in Operations. However, you must still ensure that your contracts cannot be manipulated by re-entrancy attacks.

    For example, some re-entrancy attacks take advantage of applications that store logic in multiple contracts. Attackers may send multiple transactions to a single contract before it can update other contracts or get information from them. If a group of contracts that store tokens use one contract to accept withdrawal requests and another to store balances, an attacker might be able to submit multiple withdrawals before the balance is updated.

  • Sandwich attacks: Also known as MEV attacks or front-running, sandwich attacks take advantage of the fact that incoming transactions are publicly visible. If an attacker sees a large cryptocurrency trade, they may be able to insert transactions before and after it to make a profit. In some cases, bakers can make a profit by ordering transactions in a certain way or inserting their own transactions in blocks that they create.

    To avoid this kind of attack, use Tezos timelocks or another way to order transactions fairly, or use Etherlink, which has a fair sequencer.

  • Using centralized oracles: Because smart contracts can't access data from outside the blockchain, including calling external APIs, they use oracles to provide the data. For example, some contracts use oracles to provide random values; see Using randomness safely. It's important to use oracles that are secure and trustable, otherwise they open your contract to manipulation.

    Trustable oracles average multiple sources of data like currency prices to ensure that the information does not rely on a single source. Then they use encryption to sign data and prove that it is authoritative. For ways to set up oracles to be trustable, see Using and trusting oracles on opentezos.com.