Testnet · Mainnet coming soon

Issue a private stablecoin

13 min read

View as Markdown
Contents

You issue a stablecoin backed by USDC whose balances and payments are private. On Ethereum, you deploy a reserve vault that holds the USDC and a deny-list contract, and create your list on it. On PCASH you deploy nothing: you define an asset whose mint rule, the standard deposit mint, names your vault, and whose transfer rule, the standard sender deny list, names your list. Holders' wallets mint their own deposits, so you never learn who holds what, and holders pay each other in the same crowd as every PCASH payment. You keep the controls a stablecoin needs: who may deposit, credits for wires, redemptions, and freezing stolen funds. Ethereum shows every unit issued and every unit paid out.

How it works

  1. The issuer deploys the vault and the deny-list contract and creates its list.
  2. The issuer defines the stablecoin, shares its definition, and sets who may deposit to the vault and how much.
  3. A holder's wallet makes a deposit code, and a depositor calls deposit on the vault with it.
  4. The holder's wallet finds the deposit in the vault's logs and mints it to itself.
  5. Holders pay each other the way they pay PCASH.
  6. The issuer credits a wire through the vault, without USDC, and the holder's wallet mints the credit like a deposit.
  7. A holder sends units to the issuer with a redeem 0x… memo, and the issuer's service burns them and pays USDC from the vault.
  8. The issuer freezes addresses on its list, and its service publishes the list again every 15 minutes so transfers keep flowing.

Open the wallets

The issuer's service runs on a PCASH wallet, which receives redemptions, and each holder has one. Each needs an Ethereum log reader: the wallet finds deposits in the vault's logs and reads the deny list that every send proves against. Without one, a wallet can neither mint deposits nor send the stablecoin.

/** A wallet that reads the vault's deposits and the deny list from Ethereum. The issuer and every holder open one. */
export function openWallet(dataDir: string, nodeUrl: string, ethereumKey: Hex, ethereum: PublicClient): Promise<Wallet> {
  return openNodeWallet({
    dataDir, node: nodeUrl, signer: privateKeyPcashActionSigner(hexToBytes(ethereumKey)),
    provers: createWalletProvers("native"), l1Logs: viemL1LogReader(ethereum),
  });
}

Deploy the vault and the deny list

The contracts ship in the repository and are deployed unchanged. USDC is the reserve token's address and ISSUER_ADDRESS is the address of ISSUER_KEY. The vault's last constructor argument is the cap per deposit, which the issuer sets in the next step.

cd stablecoin/l1-contracts
forge soldeer install --config-location foundry
forge create src/DenyList.sol:DenyList --rpc-url "$ETH_RPC_URL" --private-key "$ISSUER_KEY" --broadcast
forge create src/ReserveVault.sol:ReserveVault --rpc-url "$ETH_RPC_URL" --private-key "$ISSUER_KEY" --broadcast \
  --constructor-args "$USDC" "$ISSUER_ADDRESS" 0
  • The reserve vault holds the USDC. deposit(amount, recipientCommitment, nonce) takes USDC from an address the issuer has allowed, up to the issuer's cap per deposit, unless the issuer has paused deposits, and emits Deposit(depositor, recipientCommitment, nonce, amount). credit(recipientCommitment, nonce, amount) emits the same event from the issuer without taking USDC. payout(to, amount, redemptionId) pays each redemption once. The vault has no refund: neither it nor the issuer can tell whether a deposit was minted, so a refund could pay twice.
  • The deny-list contract holds each issuer's list of frozen addresses, its publication window and a pause flag. One contract serves any number of issuers' lists, so an issuer can create its list on one that is already deployed.

DenyListAdmin creates the list with a one-hour publication window and the writer's account as the list's issuer. The definition commits to two hours as the longest window the issuer may ever set; a publication with a longer window authorizes nothing. Every Ethereum transaction goes through an EthereumWriter, made with new EthereumWriter({ publicClient, walletClient }), which sends one key's transactions one at a time. Here one key controls the vault and the list, so the issuer's service and the list's admin share one writer.

/** Create the issuer's list on the DenyList contract with a one-hour window, and publish its empty root. */
export function createDenyList(ethereum: PublicClient, writer: EthereumWriter, denyListContract: Address): Promise<DenyListAdmin> {
  return DenyListAdmin.create({
    publicClient: ethereum, writer, contract: denyListContract,
    salt: `0x${randomBytes(32).toString("hex")}`, delta: 3600n, maxDelta: 7200n,
  });
}

Define the stablecoin and open the vault

The definition names the vault in its mint rule and the list in its transfer rule. The asset ID is the definition's hash, so neither rule can change, and wallets show the stablecoin as minted once per deposit to the vault and frozen through the list. The metadata's content digest commits to the stablecoin's terms.

/** Minted once per deposit to `vault`, with senders screened by the list. The asset ID is this definition's hash. */
export function defineStablecoin(vault: Address, denyList: DenyListAdmin): AssetDefinition {
  return stablecoinDefinition({
    metadata: { name: "Pilot USD", symbol: "pUSD", decimals: 6, contentDigest: createHash("sha256").update("pUSD terms").digest() },
    vault, denyList: denyList.configuration,
  });
}

The issuer publishes the definition as share text or a link. A holder's wallet keeps it under the asset ID it hashes to, and needs it to send the stablecoin, because its transfer rule names the list each send proves against.

/** The share text, on its own or in a link's `#d=` fragment. */
export function shareDefinition(definition: AssetDefinition): string {
  return formatAssetDefinition(definition);
}

/** On the holder's side: read the shared definition and keep it, so the wallet shows the stablecoin and can send it. */
export async function importStablecoin(wallet: Wallet, text: string): Promise<AssetDefinition> {
  const definition = parseAssetDefinition(text);
  await wallet.importAssetDefinition(definition);
  return definition;
}

The issuer's service, StablecoinIssuer, runs on the issuer's PCASH wallet and the vault's issuer key. It sets the vault's policy, credits, and pays redemptions, and keeps each redemption's progress in a state store so a restart resumes it. It never mints. It needs the issuer's own PCASH node: it pays out USDC on what that node reports, so a node that lied could make it pay for a redemption that never happened.

/** The issuer's service on its PCASH wallet and the vault's issuer key. Redemption progress survives a restart. */
export function openIssuer(p: {
  wallet: Wallet; nodeUrl: string; definition: AssetDefinition; ethereum: PublicClient; writer: EthereumWriter; statePath: string;
}): StablecoinIssuer {
  return new StablecoinIssuer({
    wallet: p.wallet, node: new PcashNodeClient(p.nodeUrl), definition: p.definition,
    ethereum: { publicClient: p.ethereum, writer: p.writer }, store: fileStore(p.statePath),
  });
}

/** The issuer's state in a JSON file, replaced whole on each save. */
function fileStore(path: string): IssuerStateStore {
  return {
    load: async () => existsSync(path) ? JSON.parse(await readFile(path, "utf8")) as IssuerState : { redemptions: [] },
    save: async (state) => {
      await writeFile(`${path}.tmp`, JSON.stringify(state));
      await rename(`${path}.tmp`, path);
    },
  };
}

No address may deposit until the issuer allows it. setDepositsPaused pauses deposits; credits and payouts continue.

/** Let these Ethereum accounts deposit, up to `cap` USDC units each time. */
export async function setVaultPolicy(issuer: StablecoinIssuer, depositors: readonly Address[], cap: bigint): Promise<void> {
  for (const depositor of depositors) await issuer.allow(depositor, true);
  await issuer.setDepositCap(cap);
}

A vault that let anyone deposit would make the same mint rule a permissionless way in. The way out would still trust whoever pays from the vault.

Deposit

The holder's wallet makes a fresh code for every deposit, which keeps deposits unlinkable on Ethereum. A code carries a new nonce and a commitment to the PCASH chain, the stablecoin's asset ID and the holder's PCASH address under a salt the wallet derives from its keys and that nonce, with the chain, the vault and a checksum. The wallet stores nothing: it finds its deposits in the vault's logs.

/** On the holder's side: a fresh code for each deposit, to give the depositor. */
export function depositCode(wallet: Wallet, definition: AssetDefinition): string {
  return wallet.createDepositCode({ asset: definition });
}

The depositor, whether the holder's own Ethereum account, an exchange or an employer, must be an account the issuer allowed. It approves USDC to the vault and calls deposit with the code's commitment and nonce.

/** On the depositor's side: approve USDC to the vault, then deposit to the code's commitment and nonce. */
export async function deposit(ethereum: PublicClient, depositor: WalletClient<Transport, Chain, Account>, p: {
  usdc: Address; vault: Address; pcashChainId: bigint; depositCode: string; amount: bigint;
}): Promise<Hex> {
  // Refuses a code for another PCASH chain or vault, or one with a typo.
  const code = decodeDepositCode(p.depositCode, { pcashChainId: p.pcashChainId, vault: BigInt(p.vault) });
  const approval = await depositor.writeContract({ address: p.usdc, abi: ERC20_ABI, functionName: "approve", args: [p.vault, p.amount] });
  await ethereum.waitForTransactionReceipt({ hash: approval });
  return depositor.writeContract({
    address: p.vault, abi: RESERVE_VAULT_ABI, functionName: "deposit",
    args: [p.amount, bytes32Hex(code.recipientCommitment), bytes32Hex(code.nonce)],
  });
}

Mint the deposit

PCASH derives the deposit's Ethereum block within seconds. The holder's wallet then lists its deposits and mints each one not yet minted. The proof opens the vault's log under a recent PCASH block, shows that the commitment opens to this chain, this stablecoin and the holder's address, and creates one note of the deposited amount.

/** On the holder's side: find this wallet's deposits and mint each unminted one to itself. */
export async function mintDeposits(wallet: Wallet, definition: AssetDefinition): Promise<void> {
  for (const deposit of await wallet.listDeposits({ asset: definition })) {
    if (!deposit.minted) await wallet.mintDeposit({ asset: definition, deposit });
  }
}

Each deposit mints once: its mint marker comes from the log's position and the salt, and the network accepts each marker once. The commitment names the chain and the stablecoin, so a deposit mints nothing else: not another asset that names the same vault, and not another PCASH chain that reads the same Ethereum. Only the holder's wallet can make the proof, because only it can open the commitment.

The holder needs a PCASH account, which its wallet's setup creates. While the protocol fee is waived, a holder can mint and pay with no PCASH; once it applies, each transaction burns a little PCASH, which a holder can buy on the Marketplace.

A deposit never expires: a wallet can mint it at any later time. A wallet restored from its seed finds its deposits by reading the vault's logs from the network's first Ethereum block and deriving the salt from each logged nonce, with no saved state; while it stays open, later listings read only newer blocks. If a reorganization of Ethereum removes the deposit's block, the mint goes with it, so minting needs no wait for finality.

Pay

The minted units are ordinary private notes. Holders pay each other the way they pay PCASH, and on the Marketplace they can sell them for ETH.

/** Pay another holder. A send proves against the deny list as of the wallet's last sync. */
export async function pay(wallet: Wallet, definition: AssetDefinition, to: string, amount: bigint) {
  await wallet.sync();
  return wallet.sendAsset({ assetId: assetDefinitionAssetId(definition), outputs: [{ to, amount }] });
}

Credit a wire

The issuer credits wires and replacement units with credit, given a holder's fresh deposit code and an amount. The vault emits the same Deposit event with the issuer as depositor, and the holder's wallet mints it with mintDeposits like any deposit, privately. Every unit ever issued therefore appears on Ethereum. Credits are backed by whatever the issuer received off-chain, not by the vault's USDC.

/** Credit a wire: the vault emits a deposit from the issuer, with no USDC, to the holder's fresh code. */
export function creditWire(issuer: StablecoinIssuer, holderDepositCode: string, amount: bigint): Promise<Hex> {
  return issuer.credit({ depositCode: holderDepositCode, amount });
}

The vault credits each deposit code once and reverts a second credit of the same code, so a credit the issuer retries because it never saw the first one's outcome cannot issue twice. Deposits have no such limit: two deposits with one code are two payments, and both mint.

Redeem

A holder redeems by sending units to the issuer's PCASH address with the memo redeem 0x…, naming the Ethereum address to pay. The memo is a record encrypted to the issuer.

/** On the holder's side: send units to the issuer with a memo naming the Ethereum address to pay. */
export async function redeem(wallet: Wallet, definition: AssetDefinition, issuerAddress: string, amount: bigint, payout: Address) {
  await wallet.sync();
  return wallet.sendAsset({
    assetId: assetDefinitionAssetId(definition), outputs: [{ to: issuerAddress, amount }],
    data: { recipients: [{ to: issuerAddress, records: [memoSchema.encode(redemptionMemo(payout))] }] },
  });
}

The issuer's service finds each redemption in a finalized PCASH block, burns the units, waits for the burn to be final, and pays USDC from the vault to that address. It counts a payout done once it is in a finalized Ethereum block. The vault pays each redemption ID once, so a restart or retry never pays twice. StablecoinIssuer's screen option holds a redemption until the issuer's customer checks pass.

/** Burn and pay out every minute. The service runs one call at a time and pays each redemption once. */
export function payRedemptions(issuer: StablecoinIssuer, onError: (error: unknown) => void): () => void {
  const timer = setInterval(() => issuer.processRedemptions().catch(onError), 60_000);
  return () => clearInterval(timer);
}

Freeze addresses

Every transfer and burn of the stablecoin proves that its sender is not on the issuer's list in a recent publication of the list. When the issuer freezes an address, that address can no longer send or burn the stablecoin once older publications expire, within the window the issuer set; everyone else is unaffected. A frozen address can still receive units, which then cannot leave it. The issuer can credit replacement units to a theft victim.

/** Freeze addresses: once older publications expire, they can neither send nor burn the stablecoin. */
export function freeze(denyList: DenyListAdmin, addresses: readonly Address[]): Promise<Hex> {
  return denyList.freeze(addresses);
}

DenyListAdmin also unfreezes addresses, changes the window up to the definition's maximum with setDelta, and pauses every transfer with pause until unpause.

A publication authorizes transfers only for its window, so the service publishes the unchanged list again whenever its latest publication is 15 minutes old. With a one-hour window, transfers never wait for a publication. Start the heartbeat at launch: without it, transfers stop once the latest publication grows too old. Anyone can call the contract's heartbeat, and the contract publishes only the list it stores, so no one can revive an old list.

/** Publish the unchanged list again whenever its latest publication is 15 minutes old. Run it from launch. */
export function keepListPublished(denyList: DenyListAdmin, onError: (error: unknown) => void): { stop(): Promise<void> } {
  return denyList.startHeartbeat({ onError });
}

The issuer never sees balances or transfers, and cannot take or erase a frozen balance. A freeze takes effect within the window, so a thief watching Ethereum can move funds first. The standard rule checks senders only; screening recipients needs a custom transfer rule.

What is public

  • On Ethereum: each deposit's depositor, amount and time; each credit's amount and time; each payout's address and amount; the vault's policy; and the deny list with every change to it.
  • Private: who each deposit mints to, which PCASH transaction minted it, and every balance and transfer.

Ethereum shows what the issuer owes: deposits plus credits, less payouts. It does not show how many units circulate, because deposits not yet minted and burns not yet paid out are private.

Finding and minting deposits tells the wallet's Ethereum endpoint and its PCASH node some of this:

  • Listing deposits reads every Deposit log of the vault from the Ethereum endpoint, the same requests whichever wallet lists, so the endpoint learns only that the wallet follows the vault. The wallet then asks its PCASH node whether the mint markers of its own deposits are spent, so the node learns how many deposits the wallet has and can tell the wallet's mint transactions once they land.
  • Minting a deposit reads that deposit's transaction receipt from the Ethereum endpoint and asks the PCASH node for the deposit's proof, so each learns which deposit is the wallet's.

At each sync, a holder's wallet asks its Ethereum endpoint for the deny list's logs and its PCASH node for the opening of the list's latest publication, which tells both that the wallet holds some asset under that list.

A holder who runs its own PCASH node and its own Ethereum node keeps all of this to itself. Minting soon after a deposit links the two by timing, so a holder can wait before minting. A user account's address is its owner's Ethereum address, so a deposit sent from that address points to that account.

Run it

just e2e stablecoin starts Anvil and a PCASH node and runs these steps with real proofs and one issuer key for the vault and the list: the issuer sets the vault's policy, a deposit from an allowed account mints in the recipient's wallet without naming it on Ethereum and is listed under no other asset with the same vault, a wallet restored from its keys mints an unminted deposit and a second proof of the same deposit is refused, holders pay each other, a freeze and a pause stop senders, heartbeats keep transfers flowing as Ethereum time passes, a credit mints replacement units and a repeated credit is refused, a redemption pays out USDC once, a frozen Marketplace escrow is held and then reclaimed, and a reorganization that drops a deposit drops its mint.

Further reading: the vault and deny-list contracts, the issuer's service, the end-to-end scenario, assets anyone can create and spec §11.6.