Escrow and sealed bids
Shows: the public referee (12) · seed-authorized custody (13) · the proof-carrying message (7) · windows for expiry (16)
Two different people’s private accounts cannot act in one transaction (see limits), so when two private parties exchange value, a public actor stands between them, holds the value from one transaction to the next, and has a deadline.
Part 1: escrow
Goal
Alice pays Bob for a delivery. Bob is paid when Alice confirms; if she never does, an arbiter decides. Any of the three can be private.
Actors
| Actor | What it holds | Placement |
|---|---|---|
(deal, escrow) | the addresses of buyer, seller and arbiter | public PDA |
(deal, native) | the payment | same account |
Messages
enum Message {
/// Once, by whoever sends it first. The buyer checks it, then funds the deal's account.
Open { buyer: AccountId, seller: AccountId, arbiter: AccountId, amount: u128, seed: PdaSeed },
/// A party tells their own seat what they want. The seat tells the deal.
Release { deal: AccountId },
Refund { deal: AccountId },
}
Handler
The program plays two roles, told apart by the sender.
fn handle_message(input: &ReceiveInput, message: Message) -> Response {
let program = input.receiver.program_account_id;
match (input.from, &message) {
// Role 1, a party's seat: check the owner, pass the message on.
(None, Message::Release { deal } | Message::Refund { deal }) => {
assert!(input.is_authorized(), "only the owner uses this seat");
Response::keep_state().send_sync(Actor::new(*deal, program), &message)
}
// Role 2, the deal: a seat of this program is speaking.
(Some(seat), message) => {
assert!(input.from_own_program(), "only seats speak to a deal");
let deal = Deal::from_bytes(&input.pre_state);
let who = seat.account_id;
let to = match message {
Message::Release { .. } if who == deal.buyer || who == deal.arbiter => deal.seller,
Message::Refund { .. } if who == deal.seller || who == deal.arbiter => deal.buyer,
_ => panic!("not yours to decide"),
};
Response::keep_state().send(native_token::custody_transfer(
input.receiver.account_id, deal.seed, to, deal.amount))
}
(None, Message::Open { seed, .. }) => {
assert_eq!(AccountId::for_public_pda(&program, seed), input.receiver.account_id);
Response::set_state(write_once(&input.pre_state, Deal::from(&message).to_bytes()))
}
}
}
What to notice
The deal identifies a party by a seat of its own program, never by an account id alone, which identifies nobody. The seat checks the owner’s authorization, and from_own_program() proves the sender was a seat.
A private party stays hidden: their seat presents a blinded address, the one Open recorded. The seat must present that same address every time, which the reference wallet does not (What works with the reference wallet today).
Payouts are AsyncMessages to those same addresses. The deal is public, so a payout to a private party is published in the clear and needs that address’s recovery binding on chain, unless the paying transaction is a private one that introduces it.
The arbiter is another address, which can be a person or a multisig with hidden members.
Open needs no authorization and writes once, so whoever sends it first sets the deal. The buyer reads the recorded parties and amount before funding the deal’s account.
How it runs
What leaks
The amount, the timing, and which of the three addresses ended the deal. Not who is behind a private party’s address.
Part 2: a sealed-bid auction
Goal
Bidders submit bids nobody can see. After the deadline every bid is revealed and the highest wins. A paddle’s bid cannot be changed after it is placed.
Actors
| Actor | What it holds | Placement |
|---|---|---|
(auction, auctions) | the deadline, and the revealed bids by pseudonym | public PDA |
(bidder, auctions): a paddle | the bidder’s secret amount | private, on each bidder’s account |
How it runs
- Bid. The bidder tells their paddle an amount. The paddle stores it, once, and sends the auction
Joinedunder a blinded address. - Reveal. After the deadline, the bidder tells the paddle to reveal. The paddle sends
Reveal { amount }with the amount it stored. - Settle. Anyone pokes the auction; the highest revealed amount wins. This sketch only names the winner. To make the winner pay, every bidder deposits the same amount at
Joined, at least the largest allowed bid, so the deposit says nothing about the bid; settlement pays the seller from the winner’s deposit and refunds the rest.
The paddle’s handler
Message::Bid { auction, amount } => {
assert!(input.is_authorized() && input.from.is_none());
Response::set_state(write_once(&input.pre_state, encode(&(auction, amount))))
.send_sync(auction_actor(auction), &Internal::Joined)
}
Message::RevealBid => {
assert!(input.is_authorized() && input.from.is_none());
let (auction, amount) = decode(&input.pre_state);
Response::keep_state().send_sync(auction_actor(auction), &Internal::Reveal { amount })
}
The auction accepts Joined before the deadline and Reveal after it, both only from its own program. It must also accept a Reveal only from an address that sent Joined, or a bidder could skip Joined and reveal an amount chosen after seeing the others. So a paddle must present the same blinded address for both messages, which the reference wallet does not (What works with the reference wallet today).
What to notice
There is no commitment to open. In the classic design a bidder publishes a hash and later reveals the amount and a salt, and the contract re-hashes. Here the bid sits in the paddle’s private state, written once, and the reveal is the paddle’s own code reading that state inside a proof. The auction trusts the amount because of who sent it.
A bidder who never reveals is not counted. That leaves a loophole: one person can run several paddles from several private accounts, place a different bid with each, and reveal only the one that suits them. Closing it takes a deposit at Joined, forfeited without a reveal, and large enough to outweigh the gain.
What leaks
How many bids there are and when each arrived; after the deadline, every revealed amount, under a pseudonym. Not who the bidders are.
Going further
- Deadlines without a clock message.
Releaseafter a timeout: the handler returns a validity window that starts at the deadline (pattern 16). - Swaps. An escrow that holds both sides’ deposits and pays each to the other when the second arrives.
- What does not work: a private order book. Matching needs someone to see both sides.