Assessment reports>Chainflip>Threat Model>Function: initialize

Function: initialize

Simply initializes SwapEndpointDataAccount to default values.

Accounts

  • swap_endpoint_data_account

    • Validation: Account being initialized — no validation required.

    • Impact: N/A.

  • signer

    • Validation: Account is signer.

    • Impact: N/A.

Instruction parameters

N/A.

Function: x_swap_native

This function does the following:

  • Checks that the number of open event accounts is larger than the maximum-allowed event accounts

  • Adds the event-account pubkey to the list of open event accounts

  • Transfers lamports from the signer to the aggregate key account

  • Updates the event-data account with the params

Accounts

  • data_account

    • Validation: Account owner and discriminator are checked. Checked if swaps are suspended.

    • Impact: N/A.

  • agg_key

    • Validation: Key validated through data_account.

    • Impact: Lamports from the native swap are sent to this account.

  • from

    • Validation: Account is a signer.

    • Impact: Lamports are sent from this account.

  • event_data_account

    • Validation: Newly initialized account — no validation required.

    • Impact: Stores data for the swap.

  • swap_endpoint_data_account

    • Validation: Account owner and discriminator are checked.

    • Impact: Stores the pubkey for the event-data account.

Instruction parameters

  • swap_native_params

    • The amount and decimals values in the structure are used to transfer lamports from the signer.

    • The amount is checked to be larger than the minimum native swap amount.

    • The remaining values are stored in the event-data account, and no validation is performed.

Function: x_swap_token

This function does the following:

  • Checks that the number of open event accounts is larger than the maximum-allowed event accounts

  • Adds the event-account pubkey to the list of open event accounts

  • Transfers lamports from the signer to the aggregate key account

  • Updates the event-data account with the params

Accounts

  • data_account

    • Validation: Account owner and discriminator are checked. Checked if swaps are suspended.

    • Impact: N/A.

  • agg_key

    • Validation: Key validated through data_account.

    • Impact: Lamports from the native swap are sent to this account.

  • from

    • Validation: Account is a signer.

    • Impact: Lamports are sent from this account.

  • event_data_account

    • Validation: Newly initialized account — no validation required.

    • Impact: Stores data for the swap.

  • swap_endpoint_data_account

    • Validation: Account owner and discriminator are checked.

    • Impact: Stores the pubkey for the event-data account.

Instruction parameters

  • x_swap_token

    • The amount and decimals values in the structure are used to transfer lamports from the signer.

    • The amount is checked to be larger than the minimum native swap amount.

    • The remaining values are stored in the event-data account, and no validation is performed.

Function: x_swap_token

This function does the following:

  • Checks the mint from the SupportedToken account

  • Checks that the number of open event accounts is larger than the maximum-allowed event accounts

  • Adds the event-account pubkey to the list of open event accounts

  • Transfers tokens from the user to the token vault

  • Updates the event-data account with the params

Accounts

  • data_account

    • Validation: Account owner and discriminator are checked. Checked if swaps are suspended.

    • Impact: N/A.

  • token_vault_associated_token_account

    • Validation: Checked to be the correct ATA through the mint and authority from the data account.

    • Impact: Tokens to swap are transferred to this token account.

  • from

    • Validation: Account is a signer.

    • Impact: Signer for the token account.

  • from_token_account

    • Validation: Account checked to be owned by the signer.

    • Impact: Tokens to be swapped are sent from this token account.

  • event_data_account

    • Validation: Newly initialized account — no validation required.

    • Impact: Stores data for the swap.

  • swap_endpoint_data_account

    • Validation: Account owner and discriminator are checked.

    • Impact: Stores the pubkey for the event-data account.

  • token_supported_account

    • Validation: Account owner and discriminator are checked.

    • Impact: Used to check if the token swapped from is supported.

  • mint

    • Validation: Mint is checked within the instruction logic.

    • Impact: N/A.

Instruction parameters

  • swap_native_params

    • The amount and decimals values in the structure are used to transfer lamports from the signer.

    • The amount is checked to be larger than the minimum native swap amount.

    • The remaining values are stored in the event data account, and no validation is performed.

close_event_accounts

This function does the following:

  • Iterates through the remaining accounts to fetch SwapEvent accounts and payee accounts

  • Checks that both accounts are writable

  • Tries to deserialize the event account but emits a failure in case of failed deserialization due to a reorg

  • Checks that the payee key is equal to event_account.sender

  • Closes the event account and refunds the rent to the original payee

  • Gets the index for the event account key from swap_endpoint_data_account

    • Deletes the index from swap_endpoint_data_account

    • Computes the new size by subtracting the pubkey size

    • Verifies that the new size is larger or equal to the minimum size

    • Reallocates swap_endpoint_data_account with the new size and transfers the rent difference to the original payee

Accounts

  • data_account

    • Validation: Account owner and discriminator are checked. Checked if swaps are suspended.

    • Impact: N/A.

  • agg_key

    • Validation: Key validated through data_account.

    • Impact: N/A.

  • swap_endpoint_data_account

    • Validation: Account owner and discriminator are checked.

    • Impact: Used to check if pubkeys for event accounts are valid.

Instruction parameters

N/A.

Zellic © 2024Back to top ↑