DEV Community

Kendra Koepp
Kendra Koepp

Posted on

How to Prevent a Polygon Bridge Withdrawal Replay

To prevent a duplicate withdrawal, the Polygon PoS bridge must accept a particular Polygon burn proof only once on Ethereum. If you are used to a centralised exchange, the key difference is that you initiate the transfer from your wallet, then later claim the returned tokens by proving the Polygon transaction happened.

What happens when you withdraw tokens?

For a typical Polygon PoS withdrawal, tokens are burned on Polygon first. After the burn is included in a checkpoint submitted to Ethereum, a proof of the transaction can be presented to Ethereum’s RootChainManager, which checks that the burn and its receipt are valid before the corresponding Ethereum tokens are released.

The Polygon Bridge transfer is a way to handle this Ethereum-to-Polygon or Polygon-to-Ethereum movement. For a withdrawal, expect two distinct stages: the Polygon burn and the Ethereum claim. The claim has to wait until a checkpoint covers the burn, and Ethereum gas is needed to submit it.

How does the bridge stop the same claim twice?

RootChainManager records a fingerprint for each exit proof. In Polygon’s pos-portal contract code, that fingerprint is a hash of the Polygon block number, the receipt’s Merkle-proof path (the branch mask), and the log’s position within the receipt (receipt log index). Together, these identify the event being claimed.

Before releasing tokens, the contract checks that the proof connects the receipt to a checkpoint and that the fingerprint has not already been processed. It then marks the exit as processed and calls the token contract to release the funds. If someone submits the same proof again, the stored record triggers an “exit already processed” rejection, so the same burn cannot release the tokens a second time.

For example, suppose you burn 100 POL on Polygon and later claim the corresponding 100 tokens on Ethereum. Once that claim succeeds, resubmitting its proof does not release another 100 POL. A separate valid burn has a different event location and proof; merely changing a detail in an old proof cannot make its original event new.

What should you check before claiming?

Replay protection prevents duplicate claims; it does not make an invalid proof valid or reverse a mistaken withdrawal. Check that the burn transaction succeeded and that the proof refers to the intended token and recipient. Polygon’s contract code verifies receipt and checkpoint inclusion, while ChainSecurity’s Polygon PoS Portal audit describes the proof based flow from Polygon withdrawals to Ethereum claims.

A duplicate claim can still cost gas: Ethereum processes the transaction far enough to reject it, and the sender pays for the work used. My practical tip is to save the burn transaction hash and check whether its exit is already processed before submitting another claim.

Top comments (0)