Inspiration
Motivation fades; money doesn't. Stake-based habit apps proved that putting a deposit on your own goal works: follow through and you get your money back, plus a share of what the quitters left behind. But every one of these apps runs on trust. A company holds the deposits, decides who finished, and calculates the payouts. Users can't verify any of it.
That is exactly the kind of problem blockchains exist to solve. So we asked: what if the pot belonged to nobody, and the payout rules were code that no one could change?
What it does
Lock&Run turns a running goal into a room on Solana. Friends set a distance, a number of runs, a deadline and a USDC stake, then deposit from their own wallets into a vault owned by a program-derived address (PDA). No person, server or company key can move those funds.
Runners check in from their phone with live GPS and a live camera photo, or import a run from Strava. Each proof is fingerprinted on-chain with the Memo program. When the room ends, the verifier reports who finished, and our Anchor program alone decides how much everyone gets and pays it out. If nobody finishes, or if no result arrives within 72 hours, every stake is refunded on-chain.
Brands can sponsor a challenge with a USDC bonus that goes into the same vault. Winners can spend their USDC in an in-app shop, and streaks and a weekly ranking keep people coming back.
How we built it
The program: lockrun_escrow (Rust + Anchor 0.31.1). The program has eight instructions: create_room, join_room, fund_sponsor, record_result, finalize, claim, return_sponsor and claim_fee. It is deployed on Solana Devnet at DNCsEVz5mRUwJTKpXE1z478PSxKSrRVVW2GMAr3ByDAj.
- The room PDA owns the vault. Every payout is an SPL Token CPI signed with the room's seeds (
CpiContext::new_with_signer). - The rules are fixed at creation. Stake, reward mode, schedule, verifier and fee recipient cannot change once the room exists.
- Participant and sponsor PDAs make double joins and double funding impossible by construction.
- Anchor constraints (
has_one,token::mint,token::authority) pin every account, soclaimcan only pay the recorded wallet's own token account. - Claims are permissionless. Anyone can crank a payout, and the money still only ever reaches its rightful owner.
- Anchor events (
RoomCreated,Joined,Finalized,Claimed, and more) are emitted for indexers.
Settlement math, enforced on-chain. All amounts are integer micro-USDC. In all-or-nothing mode, with $N$ runners staking $D$ each, $W$ finishers and sponsor bonuses $B$:
$$ \text{fee} = \left\lfloor 0.05 \cdot (N - W)\,D \right\rfloor, \qquad \text{share} = \left\lfloor \frac{N D + B - \text{fee}}{W} \right\rfloor $$
The remainder $(ND + B - \text{fee}) \bmod W$ is paid out one micro-unit at a time to the earliest finishers, so the vault always pays out exactly what it holds. In by-fraction mode, a runner with completion rate $r$ gets back
$$ \text{back}(r) = \begin{cases} D & r \ge 0.85 \ \lfloor D \cdot r \rfloor & r < 0.85 \end{cases} $$
and each finisher receives $D + \left\lfloor \frac{\sum_i (D - \text{back}_i) + B}{W} \right\rfloor$. The math lives in a pure Rust module that is unit-tested on the host and mirrored exactly by the app.
The client (Next.js 14 + TypeScript).
- Wallets. Phantom and Solflare connect through Wallet Standard, and sign-in uses a single-use, origin-bound message signature.
- Transactions. Deposits are versioned (v0) transactions with explicit Compute Budget limits. The room creator signs
create_roomandjoin_roomin one transaction. - A trust-minimized signing flow. The server simulates each transaction, and the browser then independently re-derives every PDA from the program ID and compares every instruction byte before the wallet is ever asked to sign. A compromised server cannot slip in a different recipient or amount.
- The settlement crank. It reads on-chain state before every step, so a retry resumes exactly where it stopped. The program itself rejects double claims.
Challenges we ran into
- Taking power away from our own server. Our first version used a server-held escrow wallet, which meant users had to trust us. Rebuilding custody around a PDA vault forced us to split responsibilities cleanly. The server only attests who finished; the program computes and pays. Even a fully compromised verifier cannot choose amounts or withdraw funds.
- Designing for the server disappearing. A trustless escrow has to survive its operator going offline. We added a timeout after which finalizing becomes impossible and everyone can reclaim their stake and sponsor bonuses. Finalizing and refunding are mutually exclusive by design.
- Rounding without leaking a single micro-USDC. Splitting $49$ USDC among $3$ finishers yields $16.333334 + 16.333333 + 16.333333$. We wrote a conservation test asserting that $\sum \text{payouts} + \text{fee} = ND + B$ for every combination of runners and finishers up to 11 participants.
- What the wallet shows vs. what gets signed. Our early simulation path silently swapped the blockhash, so Phantom could preview a different message than the one we simulated. We rebuilt the flow around fresh unsigned v0 messages and hand the wallet the exact simulated bytes.
- Off-chain proof of an on-chain bet. Running happens in the physical world. We layered server-issued run sessions, live-only camera capture, pace bounds (2:30 to 20:00 per km) and a review queue for suspiciously fast runs. Each accepted proof is stamped on-chain via memo.
Accomplishments that we're proud of
- A real, deployed Anchor program. It is live on Devnet, and the on-chain binary matches our local build.
- End-to-end flow from the app to the chain. A room is created and joined through our web app in a single wallet-signed.
- No custodian, anywhere. Stakes, sponsor bonuses, payouts, platform fees and refunds all move under program rules alone.
- Every failure path is on-chain. Nobody finishes? Everyone is refunded. The verifier vanishes? The timeout refunds everyone. A wrong payout destination? Rejected by account constraints.
- A business model on the same rails. Sponsors fund bonuses in USDC, and winners spend their USDC with those same brands in the in-app shop.
What we learned
We learned how to think in PDAs, signer seeds and CPIs, and that much of a Solana program's security lives in its account constraints rather than its instruction logic. We learned that "the user signed it" is only as safe as what the wallet actually showed them. Most of all, we learned that trustlessness is a design discipline: every feature has to answer the question, "what happens if we, the builders, act maliciously or disappear?"
What's next for Lock&Run
- Security audit and mainnet launch. We plan to move from Devnet test USDC to real USDC.
- Decentralized verification. We want to replace the single verifier with multiple independent attestors or signed device attestations (HealthKit / Core Motion), so even who finished no longer depends on one party.
- An event indexer. Our program already emits Anchor events, and we plan to consume them for real-time room updates and a public, verifiable challenge history.
- Fully chain-native clients. The browser will read each room's stake and status directly from the chain, and anyone will get a one-tap timeout refund button.
- A native iOS app. On-device motion and health data will make run proofs harder to fake.
- On-chain sponsor rewards. Single-use vouchers and redemptions will be settled on Solana, so brand campaigns are as transparent as the stakes themselves.
Built With
- anchor
- next.js
- node.js
- react
- redis
- rust
- solana
- typescript
- vercel