Skip to content

Encrypt for an auditor (ElGamal + proof)

View Markdown

Use this when an authority must be able to read a value, and the sender must not be able to lie about it: a tax authority reading salaries, an auctioneer reading bids, a regulator reading transfer amounts.

The sender encrypts the value to the auditor’s public key with exponential ElGamal, and a Groth16 proof shows the ciphertext holds the same value as the public commitment (or satisfies a rule, such as “a bid between the reserve and the deposit”). A validator checks the proof, so a transaction with a fake auditor copy never lands on-chain.

Encryption · step 1 / 5
Sendersencrypt to the public key
Alice's amountSECRETHIDDEN4,200████████
Bob's amountSECRETHIDDEN2,500████████

Anyone can encrypt with the public key. Only the secret key opens the result.

Public ledgeranyone can read it
public key PKPUBLIC0x4158…ab07
Enc(Alice) = (A, B)PUBLIC0x3b8b…e711
Enc(Bob) = (A, B)PUBLIC0xa271…b8ac
sum of ciphertextsPUBLIC0x6a55…8892

Adding ciphertexts adds the amounts inside. Nobody had to decrypt anything.

AuditorTrusteesholds the secret keyeach holds one share
secret key skSECRETHIDDEN0x195a…09e4████████
Decrypt the sumB − sk·A = 6,700·Glook up 6,700 in a table of small numbersOnly small amounts (up to 2³² here) can be looked up, so values are kept small or split into limbs.
Pick who takes part (need 2 of 3)
0 of 3: not enough shares, nothing decrypts

1. Key

An auditor makes a key pair and publishes the public key. Think of a lockbox with a slot: anyone can drop something in, only the auditor has the key.

2. Encrypt

Alice encrypts her amount to the auditor's public key and publishes the ciphertext. Each encryption uses fresh randomness, so encrypting the same amount twice gives unrelated ciphertexts. Press "Encrypt again".

3. Add

Bob does the same. Because this is exponential ElGamal, adding two ciphertexts gives a ciphertext of the sum. A ledger can keep a running encrypted total that nobody can read.

4. Decrypt

The auditor uses the secret key to recover the total. Decryption ends in a lookup, which is why encrypted amounts must be small numbers, such as votes or 32-bit limbs.

5. Split the key

To stop any one party reading the ciphertexts, trustees run a distributed key generation: nobody ever holds the whole secret key. Decrypting needs 2 of 3 trustees to cooperate. Pick trustees to try it.

SECRET only its owner knows itPUBLIC anyone can see itKey and ciphertext values are illustrative.
PartyLearns
SenderThe value
AuditorThe value, by decrypting; guaranteed to match the commitment
Everyone elseA 64-byte ciphertext and a proof; never the value

The circuit ties one secret amount to both the public commitment and the public ciphertext:

AuditedAmount.java
import org.zeroj.circuit.annotation.*;
import org.zeroj.circuit.lib.zk.ZkElGamal;
import org.zeroj.circuit.lib.zk.ZkElGamalPublicKey;
import org.zeroj.circuit.lib.zk.ZkPedersenCommitment;
/** "The ciphertext encrypts, under the auditor's key, the amount the commitment hides." */
@ZKCircuit(name = "audited-amount", version = 1)
public class AuditedAmount {
@Prove
void prove(ZkContext zk,
@Public ZkField commitU, @Public ZkField commitV,
@Public ZkField auditorU, @Public ZkField auditorV,
@Public ZkField handleU, @Public ZkField handleV,
@Public ZkField blindedU, @Public ZkField blindedV,
@Secret @UInt(bits = 32) ZkUInt amount,
@Secret @UInt(bits = 252) ZkUInt blinding,
@Secret @UInt(bits = 252) ZkUInt randomness) {
ZkPedersenCommitment.commit(zk, amount, blinding).assertAffineEquals(zk, commitU, commitV);
var auditor = ZkElGamalPublicKey.fromVerifierFixedPublic(zk, auditorU, auditorV);
ZkElGamal.encrypt(zk, amount, randomness, auditor)
.assertAffineEquals(zk, handleU, handleV, blindedU, blindedV);
}
}

On the host, the sender encrypts with ElGamal.encryptWithOpening, and the auditor admits the ciphertext only after checking that exact proof, then decrypts:

AuditorSide.java (core)
import org.zeroj.circuit.lib.jubjub.ElGamal;
import org.zeroj.circuit.lib.jubjub.ElGamalCiphertext;
import org.zeroj.circuit.lib.jubjub.ElGamalEncryption;
import org.zeroj.circuit.lib.jubjub.RawElGamalCiphertext;
// Sender: encrypt the same 250 to the auditor's key (its key context, built from a verified key),
// declaring a 32-bit message width
ElGamalEncryption enc = ElGamal.encryptWithOpening(auditor, BigInteger.valueOf(250), 32, random);
// Auditor: bytes from the chain re-enter the safe API only with a verified proof
RawElGamalCiphertext raw = RawElGamalCiphertext.decode(enc.ciphertext().encode());
ElGamalCiphertext admitted = ElGamal.admit(raw, auditor, 32,
statement -> statement.width() == 32 && proofVerifies(commitment, statement.publicInputs()));
long amount = ElGamal.decryptWithSecret(admitted, auditorSecret, (1L << 32) - 1); // 250

If the sender encrypts 1 instead of 250, no proof can be made. The full program, which shows that refusal, is in the ElGamal guide.

  • Confidential payroll. The tax authority reads every salary from the chain, and the employer can’t under-report one. (use case)
  • Sealed-bid auctions. Each bid is encrypted to the auctioneer with a proof that it’s between the reserve and the deposit, so no bidder can back out by refusing to reveal. (use case)
  • Audited transfers. Every confidential transfer carries the amount for a regulator, enforced by the transfer proof. (use case)
  • No single party should read individual values. Use split trust.
  • The value is a large number. Decryption ends in a search that only works for small values (up to about 2⁴³). Split amounts into 32-bit pieces (limbs) and encrypt each one, as the payroll and points demos do.
  • Verify the auditor’s key. Encrypt only to a key that came with a proof its owner knows the secret (VerifiedKeyShare.verify), or a rogue key could lock the auditor out.
  • Never admit ciphertexts with s -> true unless the ledger already verified that exact statement. The verifier lambda is what makes the guarantee.
  • The auditor can leak. Anyone who can decrypt can also share. Rotate keys, and consider a threshold key for high-value data.
  • Maturity. Experimental. Secret operations are offline/isolated only.