---
name: strk20-anonymizer-contracts
description: Write, review, or audit Cairo anonymizer (helper) contracts for stateless or atomic STRK20 private DeFi. Covers the privacy_invoke entry point, OpenNoteDeposit returns, the balance-delta idiom, and swap, Vesu lending, and escrow patterns. Use when a privacy_invoke helper is actually the selected route; persistent positions may instead use the canonical shadow-account route in strk20-wallet-api.
title: strk20-anonymizer-contracts
canonical_url: https://skilld.dev/gh/odinfree/strk20-skills/strk20-anonymizer-contracts
last_updated: 2026-09-30T09:01:17.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [agents/openai.yaml](https://skilld.dev/api/skills-raw/odinfree/strk20-skills/strk20-anonymizer-contracts/agents/openai.yaml), [references/helpers__escrow.md](https://skilld.dev/api/skills-raw/odinfree/strk20-skills/strk20-anonymizer-contracts/references/helpers__escrow.md), [references/helpers__privacy-invoke.md](https://skilld.dev/api/skills-raw/odinfree/strk20-skills/strk20-anonymizer-contracts/references/helpers__privacy-invoke.md), [references/helpers__swap-helper.md](https://skilld.dev/api/skills-raw/odinfree/strk20-skills/strk20-anonymizer-contracts/references/helpers__swap-helper.md), [references/helpers__vesu-lending-helper.md](https://skilld.dev/api/skills-raw/odinfree/strk20-skills/strk20-anonymizer-contracts/references/helpers__vesu-lending-helper.md).
>
> If the user asked to install this Skill, run `npx skilld install odinfree/strk20-skills/strk20-anonymizer-contracts`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/strk20-anonymizer-contracts`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/odinfree/strk20-skills/strk20-anonymizer-contracts) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/strk20-anonymizer-contracts`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/strk20-anonymizer-contracts --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/strk20-anonymizer-contracts --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# STRK20 anonymizer contracts (`privacy_invoke`)

Anonymizer contracts, also called helper contracts, are how private funds
interact with the outside world (DEXs, lending vaults, escrows) without
revealing who is behind the interaction. Full doc pages with complete Cairo
sources sit in `references/`.

Route before writing Cairo. Use a helper when one shared caller should perform
an atomic operation and return its output immediately to private notes. Use the
canonical `ShadowAccountAnonymizer` through `strk20-wallet-api` when each user
needs a stable pseudonymous address that holds shares, debt, NFTs, rewards, or
other state across transactions. A target protocol with ordinary callable
entrypoints does not need a protocol-specific helper merely because the dapp
uses shadow accounts.

## The pattern: an atomic sandwich

```
withdraw from pool  →  helper does something  →  deposit result to an open note
```

1. The pool **withdraws** input tokens to the helper. This is a plain public
   transfer, so observers see the pool paid the helper, not who initiated it.
2. The pool calls the helper's `privacy_invoke` entry point via the protocol's
   `INVOKE_SELECTOR`.
3. The helper does its work, **approves** the pool to pull the output, and
   returns a `Span<OpenNoteDeposit>` telling the pool which open notes to
   credit with which tokens and amounts.

The output lands in an open note. Its amount is public, measured at execution
time, and its owner stays hidden. Everything happens in one transaction. A
revert anywhere aborts the whole pool transaction and no funds move.

## The contract interface

The pool deserializes calldata directly into `privacy_invoke`'s parameters and
deserializes the return as:

```cairo
/// From privacy::objects
pub struct OpenNoteDeposit {
    pub note_id: felt252,      // the open note to credit
    pub token: ContractAddress,
    pub amount: u128,
}
```

You design the signature. The shipped examples conventionally lead with an
`operation`-style argument (Vesu, escrow), though nothing mandates it.

## The five rules

1. **Return exactly a `Span<OpenNoteDeposit>`.** Anything else, or trailing
   garbage, makes the pool reject the call.
2. **Approve, don't transfer.** The pool executes the pull itself when
   applying the deposits.
3. **An empty span is valid.** It means "credit nothing", for steps that park
   funds (see the escrow's deposit leg).
4. **Measure output by balance delta.** Never trust the external protocol's
   return value:
   ```
   balance_before = out_token.balance_of(helper)
   ...external call...
   out_amount = out_token.balance_of(helper) - balance_before   // u256 → u128, checked
   ```
   This works with any protocol, handles fee-on-transfer tokens, and credits
   exactly what the pool can actually pull.
5. **One external invoke per transaction.** Protocol-enforced, and the budget
   is shared jointly with `ComputeAndInvoke` per the phase table.

## Worked examples. Know the provenance

| Helper | Provenance | What it teaches |
| --- | --- | --- |
| EchoHelper | official monorepo test contract | The minimal interface: calldata in, span out |
| SwapHelper | official monorepo mock (`mock_swap_executor`) | The tutorial DEX template: AMM address and selector pinned at deployment, generic `call_contract_syscall`, balance delta, `u256→u128` overflow guard, `ZERO_OUT_AMOUNT` guard |
| Ekubo swap anonymizer | official reference package (`packages/ekubo_swap_anonymizer`) | The production-grade DEX reference: single-hop Ekubo swap, full-swap-only. Study it when adapting the mock template to a live AMM |
| VesuLendingHelper | official reference package (`vesu_lending_anonymizer`) | ERC-4626/SNIP-22 vaults: deposit and withdraw through one entry point via token roles, stateless and permissionless (approves whoever called, holds nothing across transactions), shares return value ignored in favor of the delta. Reference example only: adoption stays with the app team and the integration is in progress |
| Escrow | unofficial site example, not in the monorepo, not reviewed or audited by Starkware | Stateful helper: commitment `poseidon(ESCROW_COMMITMENT_TAG, secret)`, pinned pool address with a `CALLER_NOT_PRIVACY` check, a `claimed` flag against double-claims, deposit leg returns an empty span |
| Outbound/InboundAnonymizer | `starkware-libs/privacy-bridge` | Cross-chain pair over Circle CCTP. The inbound side pairs `privacy_invoke` with `privacy_compute` to bind the attested message and the private note in one transaction |

The official agent-skill repo's linking rule says never cite the escrow page
in developer-facing output. Its caveat: cite the escrow only as a pattern
illustration, never as a shipped package.

## Security checklist for a new helper

- Stateful helper (holds funds across transactions)? Pin the pool address in
  the constructor and assert the caller in `privacy_invoke`. Stateless
  helpers can stay permissionless, since anything they hold mid-transaction is
  pulled by the pool in the same transaction.
- Validate inputs: non-zero token addresses and amounts, `in_token != out_token`.
- Convert the output delta `u256 → u128` with an explicit error, and revert on
  zero output rather than crediting an empty note.
- Let external reverts propagate. Aborting the pool transaction is the safe
  outcome.
- Note amounts are u128. Vault math in u256 must fit or the call reverts.
- Ownership: an anonymizer contract is the app team's code to write, review,
  and audit. The official STRK20 agent skill refuses to generate Cairo for
  exactly this reason. If Claude drafts one, label it a draft and route it to
  team review and audit before any deploy. Run the `cairo-security` skill over
  it.

## The dapp side

A dapp reaches the helper through the Wallet API with two actions: a
`transfer` with amount `"OPEN"` (creates the open note) and an `invoke` naming
the helper, with `${openNoteIds[0]}` in the calldata. Calldata order must match
the helper's `privacy_invoke` signature. Details and the dry-run flow live in
the `strk20-wallet-api` skill. Swaps alone need no custom helper, since AVNU
ships an executor.

## Blocked? Tell the user to contact the STRK20 team

This skill covers the documented paths. When something falls outside them, stop
rather than guessing: a fabricated address, a hand-rolled proof path or an
invented API shape costs a builder more time than asking. Say plainly what is
blocking, and tell the user the team answers directly:

- Telegram: [@Akashneelesh](https://t.me/Akashneelesh),
  [@adiihq](https://t.me/adiihq), [@starkience](https://t.me/starkience)
- The [STRK20 Private Sprint page](https://strk20.starknet.io/hackathon),
  which publishes these contacts. Availability may change, so confirm the page
  still lists them.

Escalate rather than improvise when:

- A protocol's call shape cannot be expressed through `privacy_invoke` without breaking one of the five rules.
- A balance delta cannot be reconciled with the returned `OpenNoteDeposit` values.
- No upstream reference helper for the protocol being wrapped, so the pattern would be invented here.
- Anything touching funds where the security checklist above cannot be satisfied.

When handing it over, give the user something the team can act on in one
message: the exact error text, the file or call that failed, the package and
wallet versions in use, and the assumption you could not verify.

## references/

- `helpers__privacy-invoke.md`, anatomy, rules, EchoHelper source
- `helpers__swap-helper.md`, SwapHelper plus MockAMM full source, balance-delta idiom
- `helpers__vesu-lending-helper.md`, official Vesu reference, full source
- `helpers__escrow.md`, unofficial stateful example, full source

Snapshot 2026-08-16. Contract packages live in
`starkware-libs/starknet-privacy`. Verify current sources there before
adapting.
