Hinkal
Overview
Hinkal is the primary entrypoint to the Hinkal Protocol. It orchestrates:
zk-proof verification (Groth16 via
VerifierFacade),accounting invariants (slippage and balance conservation),
token/NFT movement (via
Transferer),UTXO and Merkle state updates (
HinkalBase),optional pre/post hook logic, and
external integrations (registered actions) — all within a single atomic transaction.
The contract itself is intentionally thin on business logic. Complex behaviors are delegated through delegatecall to hinkalInLogic.
Inheritance
IHinkalVerifierFacadeHinkalBaseDeltaAmountCalculator
Constructor
constructor(
IMerkle.MerkleConstructorArgs memory constructorArgs,
address _hinkalHelper,
address _hinkalInLogic,
address _hinkalHelperManager
)Forwards initialization to HinkalBase (Merkle tree, helper/logic addresses, roles).
Key Merkle params (via IMerkle.MerkleConstructorArgs):
levels: tree depth controlling capacityposeidon4,poseidon5: Poseidon hash contracts for commitmentsposeidon2: Poseidon for Merkle hashing
Public/External Functions
registerExternalAction
Registers a DeFi/external integration address by ID.
Effects:
externalActionMap[externalActionId] = externalActionAddress.Emits:
ExternalActionRegistered(externalActionAddress).Access:
DEFAULT_ADMIN_ROLE.
transact
Purpose: Executes a full private transaction validated by a Groth16 proof and protocol invariants.
Execution lifecycle:
Input shaping and checks
Helper constructs the exact public signals array expected by the circuit and validates metadata: token registry, relayer validity, calldata hash, access token membership, etc.
Proof gate
verifierId = buildVerifierId(dimensions, externalActionId)binds the verifier to circuit shape and the chosen external integration. Prevents proof reuse across different op types or dimensions.verifyProofenforces cryptographic validity over the supplied public signals.
State root gate
rootHashExists(rootHashHinkal)checks the Merkle root is one of the recent known roots, enabling proofs against a sliding window of historical states.
Pre-effects and hooks
performSideEffectscan e.g. store per-tx metadata, validate fees, or record intent prior to balance movement.Optional
preHookContractruns custom logic (e.g., additional allowlists or rate limits).
Balance snapshots and approvals
oldBalancesare captured to compute deltas after execution.If
doPreTxApprovalis true,_handleApprovalUtxosresolves approval deltas per token based on approval UTXOs consumed/created in the logic.
Execution branch
Internal:
_internalTransacthandles pure deposits/withdrawals with fee accounting.In-Hinkal:
_inHinkalTransactdelegates to logic for complex internal behaviors (netting, reorg of UTXOs, buffered approvals, etc.).External:
_internalRunExternalActionvalidates the action mapping and delegates to logic which performs external protocol calls atomically.
Build on-chain commitments
Any returned
UTXO[]from the logic path are converted to commitments and later appended to the Merkle tree.
Accounting invariants (per token index i)
Slippage guard: minimum received amount enforced.
Conservation equation: ensures on-chain balance delta equals the sum of off-chain proof changes, on-chain UTXO creations, approval changes, and execute-time approval effects.
This double gates both economic correctness and circuit-contracted intents.
Post hook and state writes
Optional
afterTransacthook executes with fullcircomData.insertNullifiersdefends against replay by marking spent nullifiers.insertCommitmentsappends commitments and emits events for indexers.
Reverts:
"Invalid Proof"
"Hinkal Root Hash is Incorrect"
"slippage param is violated"
"Balance Diff Should be equal to sum of onchain and offchain created commitments"
prooflessDeposit
Purpose: Deposit funds and create UTXOs without a zk-proof for simpler onboarding.
Flow:
Validation only (no proof): token registry, array shapes, and receiver structures.
Delegate to logic for UTXO building and transfer handling (including ETH semantics via
Transferer).Commitments created on-chain are appended to the Merkle tree and emitted.
Use when UX simplicity is preferred over full private spend logic (e.g., first-time deposits to a stealth address).
Security Considerations
nonReentrantguards on state-changing entrypoints.Strong zk-proof verification with dynamic
verifierIdbuilt fromDimensionsandexternalActionId.Merkle root validation for state consistency.
Per-token slippage guard and conservation equation.
Replay protection via nullifiers.
Allowlist for external actions via
externalActionMap.
Worked Scenarios
Private withdrawal with relay fee:
Circuit proves spend of UTXOs and outputs with
amountChanges[i] < 0for a token that equals thefeeToken._internalTransactcomputesrelayFee = helper.calculateRelayFee(...), enforces it does not exceed withdrawal, pays relay, and sends the remainder toexternalAddress.Balance equation validates that the on-chain delta equals proof off-chain change plus any on-chain UTXO creations and approval adjustments.
External AMM swap:
User submits proof binding
externalActionId = idand slippage thresholds._internalRunExternalActionensuresexternalAddress == ammAddress, delegates execution to logic (which performs the AMM call), returns new UTXOs, and then the Merkle tree is updated.
Helper (
IHinkalHelper): checks, side-effects, fee computation.Logic (
IHinkalInLogic): complex flows, proofless deposits, approval handling, external actions.Hooks:
IPreTransactHookandITransactHook.Verifier management via
VerifierFacade.
Common Revert Reasons
"Invalid Proof"
"Hinkal Root Hash is Incorrect"
"slippage param is violated"
"Balance Diff Should be equal to sum of onchain and offchain created commitments"
"Deposit should come from the sender"
"Relay Fee is over withdraw amount"
"relay not paid"
"Unknown externalAddress"
Last updated

