> For the complete documentation index, see [llms.txt](https://hinkal-team.gitbook.io/hinkal/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hinkal-team.gitbook.io/hinkal/protocol/transactions/deposits-and-withdrawals.md).

# Deposits & Withdrawals

Depositing and withdrawing are the two core operations in Hinkal. Both follow the same path: an off-chain proof, a single on-chain call to `transact`, and a set of checks and state updates inside the contract. See [Compliance](/hinkal/security-and-compliance/compliance.md) for deposit eligibility.

***

#### **Flow**

1. **Generate the proof off-chain**\
   The user's client produces a Zero-Knowledge Proof (ZKP) for the operation.
2. **Submit on-chain**\
   The proof is sent to the Hinkal contract's `transact` function, together with a calldata hash (see *Frontrunning protection* below).
3. **The contract verifies**\
   It checks the proof, verifies the root hashes of both the Hinkal Merkle tree and the Access Token Merkle tree, and confirms the protocol's balances are accurate.
4. **The contract updates state**\
   Commitments tied to the provided nullifiers are nullified so they cannot be reused; new commitments are added to Hinkal's Merkle tree.
5. **Funds move**
   * ***Deposit*** - the user's funds are transferred into the Hinkal contract.
   * ***Withdrawal*** - the contract pays any relayer fee (if a relayer is involved), then transfers the remaining funds to the recipient.

***

#### **Frontrunning protection**

A calldata hash is submitted alongside the ZKP. It commits the proof to the exact transaction details - including the relayer - so they cannot be altered in flight.

<figure><img src="https://400260740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUoGzqKrjqkoPsx76Zeb7%2Fuploads%2Fgit-blob-99358bca82108887a6f86c1fa0c4f3a020a894a9%2Fimage%20(67).png?alt=media" alt=""><figcaption><p>Deposit</p></figcaption></figure>

<figure><img src="https://400260740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUoGzqKrjqkoPsx76Zeb7%2Fuploads%2Fgit-blob-81a3553ec52d93eeac18cdc03bc6fecc7f4b2d13%2FWithdrawal.png?alt=media" alt=""><figcaption><p>Withdrawal</p></figcaption></figure>
