Developers

Contracts

The full external surface of OpaquePool, HonkVerifier and Poseidon2Hasher.

Copy Markdown

Source: github.com/opaque-sh/opaque/contracts/src. Addresses are on Deployments.

OpaquePool

0xC4dd454637180954857E75DA595645145FCE189B

Structs

solidity
struct ExtData {
    address recipient;   // receives the exit
    address caller;      // zero means anyone may submit
    uint256 fee;         // relayer fee, in shares
    bytes data;          // must be empty for now
    bytes ciphertext0;   // encrypted output note 0
    bytes ciphertext1;   // encrypted output note 1
}

struct Transaction {
    uint256 root;            // tree root the proof is against
    uint256[2] nullifiers;   // spent notes
    uint256[2] commitments;  // new notes
    uint256 assetId;         // always 1 ($OPA)
    uint256 exitAmount;      // value leaving the pool, 0 for a private transfer
    ExtData ext;
}

Write functions

SignatureDescription
shroud(uint256 stub, uint256 amount, bytes ciphertext) returns (uint32 index)Deposits amount $OPA into a note completed with stub. Reverts while deposits are paused or above the cap
transact(Transaction t, bytes proof)Spends up to two notes and creates two. With exitAmount set it unshrouds, paying the exit fee
donate(uint256 amount)Adds $OPA to the vault backing without minting shares. Works while deposits are paused
setDepositsPaused(bool paused)Guardian only. Pauses or resumes new shrouds. Nothing else

The pool rejects plain ETH transfers (receive reverts with EthNotAccepted).

Tree and nullifier views

SignatureDescription
currentRoot() returns (uint256)Latest tree root
isKnownRoot(uint256 root) returns (bool)True if root is among the last ROOT_HISTORY roots
rootIndex() returns (uint32)Position of the current root in the history ring
nextIndex() returns (uint32)Index the next note will take
nullifierSpent(uint256) returns (bool)True if a nullifier has been used

Deposit and pause views

SignatureDescription
depositCap() returns (uint256)Current deposit cap
capSchedule() returns (uint128 initialCap, uint128 stepAmount, uint64 stepInterval, uint128 maxCap)The cap schedule
launchTime() returns (uint256)Start of the cap schedule (unix)
depositsPaused() returns (bool)Whether new shrouds are paused
guardian() returns (address)The address allowed to pause shrouds

Value and fee views

SignatureDescription
backing() returns (uint256)$OPA held for shrouded notes
units() returns (uint256)Total shares outstanding
sharesForTokens(uint256 amount) returns (uint256)Converts $OPA to shares
tokensForShares(uint256 shares) returns (uint256)Converts shares to $OPA
exitFeeBps() returns (uint256)Exit fee in basis points
exitFeeFor(uint256 tokens) returns (uint256)Exit fee charged on tokens

Wiring and constants

SignatureDescription
token() returns (address)The $OPA token
hasher() returns (IHasher)The Poseidon2 hasher
verifier() returns (IVerifier)The proof verifier
ASSET_ID() returns (uint256)Asset id of $OPA
BPS() returns (uint256)Basis point denominator
MAX_EXIT_FEE_BPS() returns (uint256)Upper bound on the exit fee
DEPTH() returns (uint256)Tree depth
ROOT_HISTORY() returns (uint256)Number of recent roots accepted
ZERO_LEAF() returns (uint256)Value of an empty leaf

Helpers

SignatureDescription
publicInputs(Transaction t) returns (bytes32[] p)The public inputs the verifier checks
extDataHash(ExtData e) returns (uint256)Hash of the ext data bound into the proof

Both are exposed so clients and tests build the same values the contract checks.

Events

SignatureDescription
NoteAdded(uint256 indexed index, uint256 commitment, bytes ciphertext)A note joined the tree. Wallets rebuild the tree and find their notes from this
NullifierSpent(uint256 indexed nullifier)A note was spent
Shrouded(address indexed from, uint256 indexed index, address indexed asset, uint256 amount, uint256 units)A shroud deposit
Exited(uint256 indexed nullifier, address indexed recipient, address indexed asset, uint256 amount)An unshroud payout
Donation(address indexed from, address indexed asset, uint256 amount)A donation to the backing
AssetRegistered(uint256 indexed assetId, address indexed asset, bool shareBased)An asset registered at deployment

Errors

ErrorRaised when
DepositsPaused()A shroud while the guardian has paused deposits
NotGuardian()Someone else calls setDepositsPaused
UnknownAsset()An asset id other than 1
BadAmount()A zero or oversized amount
NotInField()A value at or above the field size
CapExceeded()A shroud above the current deposit cap
ZeroShares()A shroud that would mint no shares
TreeFull()The note tree has no free leaves
UnknownRoot()A proof against a root outside the recent history
NullifierUsed()A nullifier already spent
DuplicateNullifier()Both nullifiers in a transaction are the same
WrongCaller()ext.caller is set and the sender is someone else
FeeTooHigh()Relayer fee plus the exit fee exceeds the exit amount
BadExit()An exit without a recipient, or a fee with no exit
ExitTargetsNotSupported()ext.data is not empty
InvalidProof()The verifier rejects the proof
TransferFailed()A token transfer fails
EthNotAccepted()ETH sent to the pool
FeeOnTransferToken()The token delivered less than requested
InsufficientBacking()An exit larger than the pool holds
Reentrancy()A reentrant call

HonkVerifier

0x01cCac633260407E9e8a0a732C4Fcded527A5E7a

SignatureDescription
verify(bytes proof, bytes32[] publicInputs) view returns (bool)Checks a proof of the transact circuit against its public inputs

Poseidon2Hasher

0xF4a67dDD3A94E27BA0e4c8955bC8852F60DA3E01

SignatureDescription
hash2(uint256 a, uint256 b) pure returns (uint256)Hashes two field elements
hash4(uint256 a, uint256 b, uint256 c, uint256 d) pure returns (uint256)Hashes four field elements