@shieldedpools/contracts
v0.2.0
Published
The Shielded Pool protocol contract and release artifacts.
Readme
Shielded Pool Contract
A 1:1 shielded wrapper for Midnight's native unshielded tokens. Lock a token, receive a private version of it, and redeem the original. For NIGHT, that private version is sNIGHT.
Features
- 1:1 backing: every mint and return is paired with a transfer of the same token and amount in the same circuit.
- Immutable:
npm run deploygives the contract no maintenance authority, an empty committee with a threshold of 1 that no signature can meet. It is impossible to change the circuits or pause the contract after deployment. - Any ledger token: one contract wraps NIGHT and any other token that uses the ledger's unshielded coins.
- Private transfers: wrapped tokens are ordinary shielded coins, which hide the sender, recipient, amount and token. A transfer's fee and time stay public.
- Public entry and exit:
shieldshows the depositor, token and amount, andunshieldshows the recipient, token and amount. Matching amounts can link the two.
Circuits
shield
Locks amount of token in the contract and mints the same amount of its wrapped token to the caller's coin key. The depositor, token and amount are public. The new coin's key stays private, which needs a fresh secret nonce for each call.
export circuit shield(token: Bytes<32>, amount: Uint<64>, nonce: Bytes<32>): ShieldedCoinInfo {
const underlying = disclose(token);
const value = disclose(amount);
receiveUnshielded(underlying, value);
return mintShieldedToken(
underlying,
value,
disclose(nonce),
left<ZswapCoinPublicKey, ContractAddress>(ownPublicKey())
);
}unshield
Takes a wrapped coin the caller pays in, checks that it wraps token, and releases the same amount of token to recipient. The recipient, token and amount are public, but whose funds paid for it stays private. The wallet funds the coin from the wrapped coins it holds and keeps the change, so amounts don't have to match an earlier shield.
export circuit unshield(token: Bytes<32>, coin: ShieldedCoinInfo, recipient: UserAddress): [] {
const underlying = disclose(token);
const paid = disclose(coin);
const to = disclose(recipient);
// Only this contract's wrapped form of `token` may release its backing.
assert(paid.color == tokenType(underlying, kernel.self()), "shielded-pools: wrong token");
assert(to != default<UserAddress>, "shielded-pools: zero recipient");
receiveShielded(paid);
sendUnshielded(underlying, paid.value, right<ContractAddress, UserAddress>(to));
}Deploying
npm ci
npm run build
export MIDNIGHT_SEED=0000000000000000000000000000000000000000000000000000000000000001
npm run -s deployThis pays the fee from the wallet with that seed, using a proof server on 127.0.0.1:6300, and fails unless the chain shows that nobody can change the contract. No maintenance key is ever created. MIDNIGHT_NETWORK picks the network, which defaults to the local one. Public networks use the deploy workflow.
License
Copyright 2026 The Shielded Pool Authors. Apache-2.0: see LICENSE. Contributions are made under the same license.
The license doesn't cover the Shielded Pool names or logos. Don't imply that your project is official or endorsed, and give a modified version its own name.
