Resources

People often ask me "How did you learn how to hack?" The answer: by reading. This page is a collection of the blog posts and other articles that I have accumulated over the years of my journey. Enjoy!

Polygon zkEVM DoS Bug- 1178

iczcPosted 2 Years Ago
  • Since Ethereum and other layer 1 blockchains are slow and expensive, there are many layer 2 (L2) protocols appearing. The idea is to roll all the transactions on the L2 EVM into a single transaction on the L1 EVM.
  • To get assets on the L2, a bridge is used. Practically, this is done by locking the assets on the L1 then submitting a Merkle Proof on the L2 to mint the same amount of tokens that are locked in the L1. Any user can call the claimAsset(), but it always goes to the proper user.
  • While reviewing the code, they noticed that the claimAsset() was built to be gasless (free). This is because a new user will not have any assets on the L2, since they are currently transferring them over. Because of this, a malicious actor could send lots of invalid free claim tx's to cause a DoS. Well, not exactly.
  • To prevent a denial of service attack the claim tx is validated before it's put into the pool. This is a good remediation for this exact problem; great job by the development team for thinking of this in advance. Next, the author pulls up the code to look for logic flaws.
  • The code below is the logic explained above. If it's free and the execution reverted, then revert the transaction.
    isFreeTx := poolTx.GasPrice().Cmp(big.NewInt(0)) <= 0
    // if the tx is free and it was reverted in the pre execution, reject the transaction
    if isFreeTx && preExecutionResponse.isReverted {
        return fmt.Errorf("free claim reverted")
    } else { // otherwise
       ...
  • There's a subtle flaw in the code above though... the transaction can have gas! Since the revert only happens when the transaction is free, we can send very little money to put the transaction into the queue unexpectedly. This bypasses the pre-execute check on the claim tx, leading to the earlier denial of service vulnerability.
  • Overall, a pretty interesting bug that required a deep understanding of the application and the protections in place. To remediate this bug, they removed the special gas logic for claims. I'm unsure how this remediates the issue and still allows people to claim stuff from the L2 for the first time though.