Updated architecture docs are now live!

Detailed Withdrawal Flow with State Transitions

Detailed Withdrawal Flow with State Transitions

spinner

State Transition Analysis:

  1. UNKNOWN → PROCESSING

    • Triggered by: authorizeWithdraw() call from WITHDRAW_AUTHORITY_ROLE

    • Requirements: Valid WithdrawMessage, contract not paused

    • State data stored: Message hash, start time, message details

    • Events emitted: WithdrawAuthorized

    • This transition initiates the withdrawal process and starts the fraud window

  2. PROCESSING → PENDING

    • Triggered by: Time passage (fraud window duration)

    • No explicit function call required

    • The status is calculated dynamically based on current time vs. start time + fraud window

    • This transition occurs automatically after the fraud window expires

    • It indicates that the withdrawal is ready to be claimed

  3. PENDING → CLOSED

    • Triggered by: claimWithdraw() call from user

    • Requirements: Fraud window expired, valid message

    • State changes: Message status set to CLOSED

    • Actions: ETH transferred from Treasury to user

    • Events emitted: WithdrawClaimed

    • This transition completes the withdrawal process

  4. PROCESSING → CLOSED (Cancellation)

    • Triggered by: deleteWithdrawMessage() call from WITHDRAW_CANCELLER_ROLE

    • Requirements: Message in PROCESSING state

    • State changes: Message deleted

    • Events emitted: WithdrawCancelled

    • This transition cancels a suspicious withdrawal during the fraud window

State Management

The CanonicalBridge contract manages withdrawal states using an enum and a mapping:

State Calculation Logic:

This function calculates the current status of a withdrawal based on its state data. The status is determined by:

  • If the withdrawal doesn't exist (startTime is 0), it's UNKNOWN

  • If the withdrawal has been explicitly closed, it's CLOSED

  • If the fraud window has expired, it's PENDING

  • Otherwise, it's still in PROCESSING

This dynamic calculation approach allows for efficient state management without requiring explicit state transitions for time-based changes.

Key Operations

Deposit Operation - Technical Implementation

The deposit function in the CanonicalBridge contract:

This function handles the deposit process, validating the parameters, transferring ETH to the Treasury, and emitting an event for L2 processing. The modifiers ensure that the function is non-reentrant, can only be called when the contract is not paused, and validates the deposit parameters.

The deposit validation modifier:

This modifier validates the deposit parameters, ensuring that the deposit amount meets the minimum requirement, and the sent ETH matches the specified amount. These validations prevent common errors and potential attacks.

Withdrawal Operation - Technical Implementation

The withdrawal authorization function:

This function authorizes a withdrawal, validating the message, storing the withdrawal information, and emitting an event. The modifiers ensure that only entities with the WITHDRAW_AUTHORITY_ROLE can call this function, it can only be called when the contract is not paused, and the withdrawal message is valid.

The claim withdrawal function:

This function allows users to claim their withdrawal after the fraud window has expired. It verifies that the withdrawal is in the PENDING state, marks it as CLOSED, handles fee distribution if applicable, and transfers the ETH to the destination address. The modifiers ensure that the function is non-reentrant and can only be called when the contract is not paused.

Administrative Operations - Technical Examples

Last updated

Was this helpful?