keep-starknet-strange / madara

Building the Integrity Web. The most modular ZK Rollup framework.
https://madara.build
MIT License
531 stars 301 forks source link

feat: handle message cancellations on L1 #1638

Open apoorvsadana opened 1 month ago

apoorvsadana commented 1 month ago

Currently, the Madara node listens to every new message on the L1 and executes the corresponding L1_HANDLER transaction. There's an edge case here related to L1 message cancellations. Currently, Starknet allows users to cancel L1 messages after a fixed L1L2_MESSAGE_CANCELLATION_DELAY (which is 5 days at the moment). This creates the following edge case

  1. User cancels the message immediately after sending it
  2. Madara reads the message at L1L2_MESSAGE_CANCELLATION_DELAY - X where X < SETTLEMENT_TIME.
  3. At L1L2_MESSAGE_CANCELLATION_DELAY, the user revokes the message
  4. Settlement happens after L1L2_MESSAGE_CANCELLATION_DELAY and state update fails because message was revoked

A simple solution to solve this would be

  1. When processing a new L1 message, check if the message has initiated the cancellation. If yes, skip the processing. (can there be any issues if the user doesn't cancel it later on + it's never processed? I don't think so but maybe we can confirm)
  2. As long as L1L2_MESSAGE_CANCELLATION_DELAY is sufficiently grater than SETTLEMENT_TIME this shouldn't cause any issue.
fishseabowl commented 1 month ago

@apoorvsadana could I take this? Thanks

apoorvsadana commented 1 month ago

Sure @fishseabowl, assigned!